Part Number Hot Search : 
TDA1519C MP7686KN YD7738 1485ETQ PM536D 3100L PM536D 100000
Product Description
Full Text Search
 

To Download SH-2A Datasheet File

  If you can't view the Datasheet, Please click here to try to view without PDF Reader .  
 
 


  Datasheet File OCR Text:
  revision date: jul 08, 2005 32 SH-2A, sh2a-fpu software manual renesas 32-bit risc microcomputer superh? risc engine family rev. 3.00 rej09b0051-0300
rev. 3.00 jul 08, 2005 page ii of xiv 1. these materials are intended as a reference to assist our customers in the selection of the renesas technology corp. product best suited to the customer's application; they do not convey any license under any intellectual property rights, or any other rights, belonging to renesas technology corp. or a third party. 2. renesas technology corp. assumes no responsibility for any damage, or infringement of any third- party's rights, originating in the use of any product data, diagrams, charts, programs, algorithms, or circuit application examples contained in these materials. 3. all information contained in these materials, including product data, diagrams, charts, programs and algorithms represents information on products at the time of publication of these materials, and are subject to change by renesas technology corp. without notice due to product improvements or other reasons. it is therefore recommended that customers contact renesas technology corp. or an authorized renesas technology corp. product distributor for the latest product information before purchasing a product listed herein. the information described here may contain technical inaccuracies or typographical errors. renesas technology corp. assumes no responsibility for any damage, liability, or other loss rising from these inaccuracies or errors. please also pay attention to information published by renesas technology corp. by various means, including the renesas technology corp. semiconductor home page (http://www.renesas.com). 4. when using any or all of the information contained in these materials, including product data, diagrams, charts, programs, and algorithms, please be sure to evaluate all information as a total system before making a final decision on the applicability of the information and products. renesas technology corp. assumes no responsibility for any damage, liability or other loss resulting from the information contained herein. 5. renesas technology corp. semiconductors are not designed or manufactured for use in a device or system that is used under circumstances in which human life is potentially at stake. please contact renesas technology corp. or an authorized renesas technology corp. product distributor when considering the use of a product contained herein for any specific purposes, such as apparatus or systems for transportation, vehicular, medical, aerospace, nuclear, or undersea repeater use. 6. the prior written approval of renesas technology corp. is necessary to reprint or reproduce in whole or in part these materials. 7. if these products or technologies are subject to the japanese export control restrictions, they must be exported under a license from the japanese government and cannot be imported into a country other than the approved destination. any diversion or reexport contrary to the export control laws and regulations of japan and/or the country of destination is prohibited. 8. please contact renesas technology corp. for further details on these materials or the products contained therein. 1. renesas technology corp. puts the maximum effort into making semiconductor products better and more reliable, but there is always the possibility that trouble may occur with them. trouble with semiconductors may lead to personal injury, fire or property damage. remember to give due consideration to safety when making your circuit designs, with appropriate measures such as (i) placement of substitutive, auxiliary circuits, (ii) use of nonflammable material or (iii) prevention against any malfunction or mishap. keep safety first in your circuit designs! notes regarding these materials
rev. 3.00 jul 08, 2005 page iii of xiv main revisions for this edition item page revision (see manual for details) 1.1 features 1 description amended the SH-2A/sh2a-fpu is a 32-bit risc (reduced instruction set computer) microprocessor that is upward-compatible with the sh- 1, sh-2, and sh-2 e at the object code level. 2.2.2 control registers (1) status register, sr 5 description amended (32-bit, initial value =0000 0000 0000 0000 00x0 00xx 1111 00xx) 3.1.1 exception handling types and priority table 3.1 exception types and priority 16 note amended notes: 1. delayed branch instructions: jmp, jsr, bra, bsr, rts, rte, bf/s, bt/s, bsrf, braf . 3.1.2 exception handling operation (2) address error, ram error, register bank error, interrupt, or instruction exception handling 18 description amended ??? and the vector table address offset of the interrupt exception handling to be executed, ??? 3.3.1 address error sources table 3.5 bus cycles and address errors 22 table amended bus cycle type bus master bus cycle operation address error occurrence data read/write cpu or dmac double longword data accessed from double longword boundary no error (normal) double longword data accessed from other than double longword boundary address error 3.6.3 interrupt exception handling 26 description amended ??? and the vector table address offset of the interrupt exception handling to be executed, ???
rev. 3.00 jul 08, 2005 page iv of xiv item page revision (see manual for details) 4.3 instruction format table 4.8 instruction formats 45 table amended instruction formats nid format nnnn xxxx xxxx 32 16 xiii dddd xxxx dddd 15 0 dddd 5.1 instruction set by classification table 5.2 instruction code format 53 table amended item format explanation instruction rm: source register rn: destination register imm: immediate data disp: displacement * 1 5.1.1 data transfer instructions table 5.3 data transfer instructions 56 table amended movml.l @r15+,rn movmu.l @r15+,rn note: when r n = r15, read r n as pr 6.2 format of instruction descriptions 76 description amended register bank structure definition ( vto: interrupt vector table address offset) 6.3.30 resbank restore from registerbank system control instruction 145 note amended * 19 when a bank overflow has occurred and the register is restored from the stack 6.4.21 dt decrement and test arithmetic instruction 196 program listing amended dt r 5 6.4.31 mov move immediate data data transfer instruction 219 description amended ??? the pc points to the starting address of the fourth byte after this mov instruction. ??? the pc points to the starting address of the fourth byte after this mov instruction, ???
rev. 3.00 jul 08, 2005 page v of xiv item page revision (see manual for details) 6.4.48 rte return from exception system control instruction 244 description amended return from exception handling delayed branch instruction 6.4.50 set t set t bit system control instruction 248 description amended t bit setting 6.4.57 sleep sleep system control instruction 257 description amended transition to power-down mode . 6.5.10 float floating-point convert from integer floating-point instruction 296 description amended ??? when fpscr.enable.i = 1, and fpscr.pr = 0, an fpu exception trap is generated regardless of whether or not an exception has occurred. ??? 7.1 overview figure 7.1 overview of register bank configuration 325 figure amended (before) ivo (after) vto figure notes amended vto: interrupt vector table address offset 7.2.1 banked data 326 description amended ??? and the interrupt vector table address offsets (vto) are banked. 7.2.2 register banks 326 description amended ??? register banks are stacked in first in last out (filo) sequence. ??? 7.2.3 bank control registers (2) bank number register (ibnr) (16 bit, initial value: h'0000) 327 description amended bits 3 to 0: bn3 to bn0 ??? after which the data is retrieved from the register bank. these bits are read-only and cannot be modified. 7.3.1 save to bank 328 description amended (b) ..., and the interrupt vector table address offset (vto) are saved to the bank indicated by the bn, bank i. figure 7.2 bank save operations figure 7.3 bank save timing 328, 329 figure amended (before) ivn (after) vto
rev. 3.00 jul 08, 2005 page vi of xiv item page revision (see manual for details) 7.4.2 register bank addressing 330 description amended ??? and the entry within the bank (r0 to r14, gbr, mach, macl, pr, vto) is specified by address bits 6 to 2 (en). figure 7.4 register bank addressing 331 figure amended (before) ivo (after) vto 8.2 slots and pipeline flow figure 8.3 impossible pipeline flow (1) 339 figure amended instruction 1 if id ex ma wb 8.6 contention due to fpu figure 8.36 example of use of result of zero- latency instruction as source 353 figure amended (before) gx (after) ex 8.9 pipeline operations for each instruction table 8.1 number of instruction stages and execution states 372 table amended type category number of stages execution states latency contention instructions 4 1 2 sts mach,rn system control instructions mac register transfer instructions ? these instruc- tions use the multiplication result read path. sts macl,rn appendix a sh- 2a/sh2a-fpu parallel execution 480, 481 table amended classifi- cation of first instruction classifi- cation of second instruction instruction mw mw stc.l vbr,@-rn sts.l pr,@- rn ex ex subc rm,rn subv rm,rn tst #imm,r0 br mr jsr/n @@( disp8,tbr)
rev. 3.00 jul 08, 2005 page vii of xiv contents section 1 overview ............................................................................................................. 1 1.1 features.................................................................................................................... ......... 1 section 2 programming model ........................................................................................ 3 2.1 data formats................................................................................................................ ..... 3 2.2 register configuration...................................................................................................... 3 2.2.1 general registers................................................................................................. 3 2.2.2 control registers ................................................................................................. 5 2.2.3 system registers.................................................................................................. 6 2.2.4 floating-point registers ...................................................................................... 7 2.2.5 floating-point system registers.......................................................................... 8 2.2.6 register banks..................................................................................................... 10 2.2.7 register initial values ......................................................................................... 10 2.3 data formats................................................................................................................ ..... 11 2.3.1 data format in registers ..................................................................................... 11 2.3.2 data formats in memory..................................................................................... 11 2.3.3 immediate data format ....................................................................................... 12 2.4 processing states ........................................................................................................... ... 13 section 3 exception handling ......................................................................................... 15 3.1 overview .................................................................................................................... ...... 15 3.1.1 exception handling types and priority............................................................... 15 3.1.2 exception handling operation ............................................................................ 17 3.1.3 exception vector table ....................................................................................... 18 3.2 resets...................................................................................................................... .......... 20 3.2.1 types of reset ..................................................................................................... 20 3.2.2 power-on reset................................................................................................... 20 3.2.3 manual reset ....................................................................................................... 21 3.3 address errors .............................................................................................................. .... 22 3.3.1 address error sources ......................................................................................... 22 3.3.2 address error exception handling...................................................................... 23 3.4 ram errors .................................................................................................................. .... 23 3.4.1 ram error sources ............................................................................................. 23 3.4.2 ram error exception handling.......................................................................... 23 3.5 register bank errors........................................................................................................ .24 3.5.1 register bank error sources................................................................................ 24 3.5.2 register bank error exception handling ............................................................ 24 3.6 interrupts.................................................................................................................. ......... 25
rev. 3.00 jul 08, 2005 page viii of xiv 3.6.1 interrupt sources.................................................................................................. 25 3.6.2 interrupt priority .................................................................................................. 25 3.6.3 interrupt exception handling .............................................................................. 26 3.7 instruction exceptions ...................................................................................................... 27 3.7.1 types of instruction exception............................................................................ 27 3.7.2 trap instruction ................................................................................................... 28 3.7.3 slot illegal instructions........................................................................................ 28 3.7.4 general illegal instructions.................................................................................. 29 3.7.5 integer division instructions ............................................................................... 29 3.7.6 floating-point operation instructions.................................................................. 29 3.8 cases in which exceptions are not accepted................................................................. 30 3.9 stack status after exception handling.............................................................................. 31 3.10 usage notes ................................................................................................................ ...... 32 3.10.1 stack pointer (sp) value ..................................................................................... 32 3.10.2 vector base register (vbr) value ..................................................................... 32 3.10.3 address errors occurring in address error exception handling stacking......... 32 section 4 instruction features ......................................................................................... 33 4.1 risc-type instruction set................................................................................................ 33 4.2 addressing modes ............................................................................................................ 37 4.3 instruction format.......................................................................................................... ... 41 section 5 instruction set .................................................................................................... 47 5.1 instruction set by classification ....................................................................................... 47 5.1.1 data transfer instructions ................................................................................... 54 5.1.2 arithmetic operation instructions ....................................................................... 58 5.1.3 logic operation instructions ............................................................................... 61 5.1.4 shift instructions.................................................................................................. 62 5.1.5 branch instructions.............................................................................................. 63 5.1.6 system control instructions................................................................................. 64 5.1.7 floating-point instructions .................................................................................. 66 5.1.8 fpu-related cpu instructions............................................................................ 68 5.1.9 bit manipulation instructions .............................................................................. 69 section 6 instruction descriptions .................................................................................. 71 6.1 overview of new instructions .......................................................................................... 71 6.2 format of instruction descriptions ................................................................................... 75 6.3 new instructions ............................................................................................................ ... 88 6.3.1 band......... bit and ...................................... bit manipulation instruction ... 88 6.3.2 bandnot bit andnot .............................. bit manipulation instruction ... 90 6.3.3 bclr ......... bit clear .................................... bit manipulation instruction ... 92
rev. 3.00 jul 08, 2005 page ix of xiv 6.3.4 bld ........... bit load ...................................... bit manipulation instruction ... 94 6.3.5 bldnot ... bit loadnot .............................. bit manipulation instruction ... 96 6.3.6 bor ........... bit or ......................................... bit manipulation instruction ... 98 6.3.7 bornot ... bit ornot ................................. bit manipulation instruction ... 100 6.3.8 bset ......... bit set ........................................ bit manipulation instruction ... 102 6.3.9 bst ............ bit store ..................................... bit manipulation instruction ... 104 6.3.10 bxor ........ bit exclusive or ......................... bit manipulation instruction ... 106 6.3.11 clips ........ clip as signed ............................ arithmetic instruction ............. 108 6.3.12 clipu ........ clip as unsigned ........................ arithmetic instruction ............. 111 6.3.13 divs .......... divide as signed ........................ arithmetic instruction ............. 113 6.3.14 divu ......... divide as unsigned .................... arithmetic instruction ............. 114 6.3.15 fmov ........ floating-point move .................. floating-point instruction........ 115 6.3.16 jsr/n ......... jump to subroutine with no delay slot ...................................................... branch instruction ................... 118 6.3.17 ldbank ... load register bank .................. system control instruction...... 121 6.3.18 ldc ........... load to control register ............. system control instruction...... 123 6.3.19 mov .......... move structure data ................... data transfer instruction......... 124 6.3.20 mov .......... move reverse stack .................... data transfer instruction......... 127 6.3.21 movi20 .... move immediate 20bits data ..... data transfer instruction......... 130 6.3.22 movi20s .. move immediate 20bits data and 8bits shift left ...................................................... data transfer instruction......... 131 6.3.23 movml.l move multi-register lower part data transfer instruction......... 133 6.3.24 movmu.l move multi-register upper part data transfer instruction......... 136 6.3.25 movrt ..... move reverse tbit .................... data transfer instruction......... 139 6.3.26 movu ....... move structure data as unsigned ...................................................... data transfer instruction......... 140 6.3.27 mulr ........ multiply to register .................. arithmetic instruction ............. 142 6.3.28 nott ........ not tbit ..................................... data transfer instruction......... 143 6.3.29 pref .......... prefetch data to cache ............... data transfer instruction......... 144 6.3.30 resbank restore from registerbank ...... system control instruction...... 145 6.3.31 rts/n ........ return from subroutine with no delay slot ...................................................... branch instruction ................... 147 6.3.32 rtv/n ....... return to value and from subroutine with no delay slot ...................................................... branch instruction ................... 148 6.3.33 shad ........ shift arithmetic dynamically .... shift instruction ....................... 150 6.3.34 shld ......... shift logical dynamically ......... shift instruction ....................... 152 6.3.35 stbank ... store register bank .................. system control instruction...... 154 6.3.36 stc ............ store control register ................. system control instruction...... 156 6.4 sh-2e cpu instructions................................................................................................... 157 6.4.1 add .......... add binary ................................ arithmetic instruction ............. 157 6.4.2 addc ........ add with carry .......................... arithmetic instruction ............. 158
rev. 3.00 jul 08, 2005 page x of xiv 6.4.3 addv ........ add with (v flag) overflow check ...................................................... arithmetic instruction ............. 159 6.4.4 and .......... and logical ................................ logical instruction................... 161 6.4.5 bf .............. branch if false ............................ branch instruction ................... 163 6.4.6 bf/s ........... branch if false with delay slot ... branch instruction ................... 165 6.4.7 bra ........... branch ....................................... branch instruction ................... 167 6.4.8 braf ......... branch far ................................ branch instruction ................... 169 6.4.9 bsr ............ branch to subroutine ................. branch instruction ................... 171 6.4.10 bsrf ......... branch to subroutine far ........... branch instruction ................... 173 6.4.11 bt .............. branch if true ............................. branch instruction ................... 175 6.4.12 bt/s ........... branch if true with delay slot .... branch instruction ................... 177 6.4.13 clrmac .. clear mac register .................... system control instruction...... 179 6.4.14 clrt ......... clear t bit .................................. system control instruction...... 180 6.4.15 cmp/cond .. compare conditionally ............... arithmetic instruction ............. 181 6.4.16 div0s ........ divide (step 0) as signed ........... arithmetic instruction ............. 185 6.4.17 div0u ....... divide (step 0) as unsigned ....... arithmetic instruction ............. 186 6.4.18 div1 .......... divide 1 step .............................. arithmetic instruction ............. 187 6.4.19 dmuls.l .. double-length multiply as signed ...................................................... arithmetic instruction ............. 192 6.4.20 dmulu.l double-length multiply as unsigned ...................................................... arithmetic instruction ............. 194 6.4.21 dt .............. decrement and test ..................... arithmetic instruction ............. 196 6.4.22 exts ......... extend as signed ....................... arithmetic instruction ............. 197 6.4.23 extu ........ extend as unsigned ................... arithmetic instruction ............. 198 6.4.24 jmp ............ jump ........................................... branch instruction ................... 199 6.4.25 jsr ............. jump to subroutine .................... branch instruction ................... 201 6.4.26 ldc ........... load to control register ............. system control instruction...... 203 6.4.27 lds ............ load to system register .............. system control instruction...... 205 6.4.28 mac.l ....... multiply and accumulate long .. arithmetic instruction ............. 207 6.4.29 mac.w ..... multiply and accumulate word arithmetic instruction ............. 211 6.4.30 mov .......... move data .................................. data transfer instruction......... 214 6.4.31 mov .......... move immediate data ................ data transfer instruction......... 219 6.4.32 mov .......... move peripheral data ................ data transfer instruction......... 222 6.4.33 mov .......... move structure data ................... data transfer instruction......... 225 6.4.34 mova ....... move effective address ............. data transfer instruction......... 228 6.4.35 movt ....... move t bit ................................. data transfer instruction......... 230 6.4.36 mul.l ....... multiply long ........................... arithmetic instruction ............. 231 6.4.37 muls.w ... multiply as signed word .......... arithmetic instruction ............. 232 6.4.38 mulu.w ... multiply as unsigned word ...... arithmetic instruction ............. 233 6.4.39 neg ........... negate ........................................ arithmetic instruction ............. 234 6.4.40 negc ........ negate with carry ...................... arithmetic instruction ............. 235
rev. 3.00 jul 08, 2005 page xi of xiv 6.4.41 nop ........... no operation ............................... system control instruction...... 236 6.4.42 not ........... not-logical complement ............ logical instruction................... 237 6.4.43 or .............. or logical .................................. logical instruction................... 238 6.4.44 rotcl ...... rotate with carry left .............. shift instruction ....................... 240 6.4.45 rotcr ...... rotate with carry right ............ shift instruction ....................... 241 6.4.46 rotl ......... rotate left ................................ shift instruction ....................... 242 6.4.47 rotr ........ rotate right .............................. shift instruction ....................... 243 6.4.48 rte ............ return from exception ............... system control instruction...... 244 6.4.49 rts ............ return from subroutine ............. branch instruction ................... 246 6.4.50 sett .......... set t bit ..................................... system control instruction...... 248 6.4.51 shal ......... shift arithmetic left .................. shift instruction ....................... 249 6.4.52 shar ........ shift arithmetic right ................ shift instruction ....................... 250 6.4.53 shll ......... shift logical left ....................... shift instruction ....................... 251 6.4.54 shlln ....... n bits shift logical left .............. shift instruction ....................... 252 6.4.55 shlr ......... shift logical right ..................... shift instruction ....................... 254 6.4.56 shlrn ....... n bits shift logical right ........... shift instruction ....................... 255 6.4.57 sleep ....... sleep ......................................... system control instruction...... 257 6.4.58 stc ............ store control register ................. system control instruction...... 258 6.4.59 sts ............ store system register ................. system control instruction...... 260 6.4.60 sub ........... subtract binary ........................... arithmetic instruction ............. 262 6.4.61 subc ......... subtract with carry .................... arithmetic instruction ............. 263 6.4.62 subv ........ subtract with (v flag) underflow check ...................................................... arithmetic instruction ............. 264 6.4.63 swap ........ swap register halves .................. data transfer instruction......... 266 6.4.64 tas ............ test and set ................................ logical instruction................... 268 6.4.65 trapa ...... trap always ............................. system control instruction...... 269 6.4.66 tst ............ test logical ................................ logical instruction................... 271 6.4.67 xor ........... exclusive or logical .................. logical instruction................... 273 6.4.68 xtrct ...... extract .................................... data transfer instruction......... 275 6.5 floating-point instructions and fpu-related cpu instructions....................................... 276 6.5.1 fabs ......... floating-point absolute value .... floating-point instruction........ 276 6.5.2 fadd ........ floating-point add .................... floating-point instruction........ 277 6.5.3 fcmp ........ floating-point compare .............. floating-point instruction........ 280 6.5.4 fcnvds ... floating-point convert double to single precision ...................................................... floating-point instruction........ 284 6.5.5 fcnvsd ... floating-point convert single to double precision ...................................................... floating-point instruction........ 287 6.5.6 fdiv .......... floating-point divide ................. floating-point instruction........ 289 6.5.7 fldi0 ........ floating-point load immediate 0.0 ...................................................... floating-point instruction........ 293
rev. 3.00 jul 08, 2005 page xii of xiv 6.5.8 fldi1 ........ floating-point load immediate 1.0 ...................................................... floating-point instruction........ 294 6.5.9 flds ......... floating-point load to system register ...................................................... floating-point instruction........ 295 6.5.10 float ...... floating-point convert from integer ...................................................... floating-point instruction........ 296 6.5.11 fmac ........ floating-point multiply and accumulate ...................................................... floating-point instruction........ 298 6.5.12 fmov ........ floating-point move .................. floating-point instruction........ 304 6.5.13 fmul ........ floating-point multiply ............. floating-point instruction........ 308 6.5.14 fneg ......... floating-point negate value ....... floating-point instruction........ 310 6.5.15 fschg ...... sz-bit change ............................ floating-point instruction........ 311 6.5.16 fsqrt ....... floating-point square root ....... floating-point instruction........ 312 6.5.17 fsts .......... floating-point store system register ...................................................... floating-point instruction........ 315 6.5.18 fsub ......... floating-point subtract .............. floating-point instruction........ 316 6.5.19 ftrc ......... floating-point truncate and convert to integer ...................................................... floating-point instruction........ 318 6.5.20 lds ............ load to fpu system register ...... system control instruction...... 321 6.5.21 sts ............ store from fpu system register system control instruction...... 323 section 7 register banks .................................................................................................. 325 7.1 overview .................................................................................................................... ...... 325 7.2 register banks and bank control registers ..................................................................... 326 7.2.1 banked data ........................................................................................................ 326 7.2.2 register banks..................................................................................................... 326 7.2.3 bank control registers........................................................................................ 326 7.3 bank save and retrieve operations ................................................................................. 328 7.3.1 save to bank........................................................................................................ 328 7.3.2 retrieve from bank.............................................................................................. 329 7.3.3 save and retrieve operations after saving to all banks .................................... 329 7.4 register bank data send instructions .............................................................................. 330 7.4.1 description of instructions .................................................................................. 330 7.4.2 register bank addressing ................................................................................... 330 7.5 register bank exceptions ................................................................................................. 332 7.5.1 register bank error sources................................................................................ 332 7.5.2 register bank error exception processing.......................................................... 332 7.6 sr register bank overflow bit (bo bit)......................................................................... 333 section 8 pipeline operation ............................................................................................ 335 8.1 basic pipeline configuration ............................................................................................ 335
rev. 3.00 jul 08, 2005 page xiii of xiv 8.2 slots and pipeline flow .................................................................................................... 3 39 8.3 instruction execution and parallel execution capability ................................................. 341 8.3.1 details of resource contention ........................................................................... 342 8.3.2 details of contention due to wait for result of previously issued instruction .. 345 8.3.3 details of register contention and flag contention ........................................... 345 8.3.4 details of contention due to multi-cycle instruction......................................... 347 8.3.5 details of contention due to 32-bit instruction.................................................. 348 8.3.6 details of contention due to instruction that uses fpscr ................................ 349 8.3.7 details of contention due to branch instruction................................................. 350 8.4 number of instruction execution states ........................................................................... 351 8.5 effect of memory load instruction on pipeline ............................................................... 352 8.6 contention due to fpu..................................................................................................... 35 3 8.7 contention due to multiplier............................................................................................ 360 8.8 programming strategy ...................................................................................................... 36 4 8.9 pipeline operations for each instruction .......................................................................... 364 8.9.1 data transfer instructions ................................................................................... 378 8.9.2 arithmetic operation instructions ....................................................................... 390 8.9.3 logical operation instructions ............................................................................ 404 8.9.4 shift instructions.................................................................................................. 412 8.9.5 branch instructions.............................................................................................. 414 8.9.6 system control instructions................................................................................. 422 8.9.7 exception handling ............................................................................................. 443 8.9.8 floating-point instructions and fpu-related cpu instructions.......................... 448 8.10 simple method of calculating required number of clock cycles.................................. 475 appendix a SH-2A/sh2a-fpu parallel execution ................................................. 479 appendix b programming guidelines (using movi20 and movi20s) .......... 483
rev. 3.00 jul 08, 2005 page xiv of xiv
section 1 overview rev. 3.00 jul 08, 2005 page 1 of 484 rej09b0051-0300 section 1 overview 1.1 features the SH-2A/sh2a-fpu is a 32-bit risc (reduced instruction set computer) microprocessor that is upward-compatible with the sh-1, sh-2, and sh-2e at the object code level. the sh2a-fpu has an on-chip floating point unit and the SH-2A does not. the use of 16-bit basic instructions enables code efficiency, performance, and ease of use to be improved. features of the SH-2A/sh2a-fpu are summarized in table 1.1. table 1.1 SH-2A/sh2a-fpu features item features cpu ? original renesas technology architecture ? 32-bit internal data bus ? general-register architecture ? sixteen 32-bit general registers ? four 32-bit control registers ? four 32-bit system registers ? register banks for fast interrupt response ? risc-type instruction set (upward-compatible with sh series) ? instruction length: 16-bit basic instructions for improved efficiency, and 32-bit instructions for improved performance and ease of use ? load-store architecture ? delayed branch instructions ? instruction set based on c language ? superscalar architecture allowing simultaneous execution of two instructions, including fpu ? instruction execution time: max. 2 instructions/cycle ? address space: 4 gbytes ? on-chip multiplier ? five-stage pipeline ? harvard architecture
section 1 overview rev. 3.00 jul 08, 2005 page 2 of 484 rej09b0051-0300 item features floating-point unit (fpu) ? on-chip floating-point coprocessor ? supports single-precision (32 bits) and double-precision (64 bits) ? supports ieee754-compliant data types and exceptions ? two rounding modes: round to nearest and round to zero ? handling of denormalized numbers: truncation to zero ? floating-point registers ? sixteen 32-bit floating-point registers (single-precision x 16 words or double-precision x 8 words) ? two 32-bit floating-point system registers ? supports fmac (multiply and accumulate) instruction ? supports fdiv (divide) and fsqrt (square root) instructions ? supports fldi0/fldi1 (load constant 0/1) instructions ? instruction execution times ? latency (fmac/fadd/fsub/fmul): 3 cycles (single-precision), 8 cycles (double-precision) ? pitch (fmac/fadd/fsub/fmul): 1 cycle (single-precision), 6 cycles (double-precision) note: fmac is supported for single-precision only. ? five-stage pipeline
section 2 programming model rev. 3.00 jul 08, 2005 page 3 of 484 rej09b0051-0300 section 2 programming model 2.1 data formats data formats supported by the SH-2A/sh2a-fpu are shown in figure 2.1. byte (8 bits) word (16 bits) longword (32 bits) single-precision floating-point (32 bits) double-precision floating-point (64 bits) 0 7 0 15 0 31 0 31 30 22 fraction exp s 0 63 62 51 exp s fraction figure 2.1 data formats 2.2 register configuration 2.2.1 general registers figure 2.2 shows the general registers. there are 16 general registers (rn) numbered r0 to r15, which are 32 bits in length. general registers are used for data processing and address calculation. r0 is also used as an index register. several instructions use r0 as a fixed source or destination register. r15 is used as the hardware stack pointer (sp). saving and recovering the status register (sr) and program counter (pc) in exception processing is accomplished by referencing the stack using r15.
section 2 programming model rev. 3.00 jul 08, 2005 page 4 of 484 rej09b0051-0300 r0 r1 r2 r3 r4 r5 r6 r7 r8 r9 r10 r11 r12 r13 r14 r15, sp 31 0 r0 functions as an index register in the indirect indexed register addressing mode and indirect indexed gbr addressing mode. in some instructions, r0 functions as a fixed source register or destination register. r15 functions as a hardware stack pointer (sp) during exception processing. 1. notes: * 1 (hardware stack pointer) * 2 2. figure 2.2 general registers
section 2 programming model rev. 3.00 jul 08, 2005 page 5 of 484 rej09b0051-0300 2.2.2 control registers there are four control registers, each 32 bits in length: the status register (sr), global base register (gbr), vector base register (vbr), and jump table base register (tbr). the status register indicates the processing status of instructions. the global base register is used as the base address in the gbr indirect addressing mode and to transfer register data from on-chip peripheral modules. the vector base register is used as the base address for the exception processing vector area, including interrupts. the table base register is used as the base address for the function table area. (1) status register, sr (32-bit, initial value = 0000 0000 0000 0000 00x0 00xx 1111 00xx) (x = undefined)) 31 15 14 13 12 10 9 8 7 4 3 2 1 0 ? bo cs ? m q imask ? s t note: ?: reserved bits. always read as 0. the write value should always be 0. bo: indicates that a register bank has overflowed. cs: indicates that, in clip instruction execution, the value has exceeded the saturation upper- limit value or fallen below the saturation lower-limit value. m, q: used by the div0s, div0u, and div1 instructions. imask: interrupt mask level s: specifies a saturation operation for a mac instruction. t: true/false condition or carry/borrow bit (2) global base register, gbr (32-bit, initial value = undefined) gbr is referenced as the base address in a gbr-referencing mov instruction. (3) vector base register, vbr (32-bit, initial value = h'0000 0000) vbr is referenced as the branch destination base address in the event of an exception or interrupt.
section 2 programming model rev. 3.00 jul 08, 2005 page 6 of 484 rej09b0051-0300 (4) jump table base register, tbr (32-bit, initial value = undefined) tbr is referenced as the start address of a function table located in memory in a jsr/n @@(disp8,tbr) table referencing subroutine call instruction. 2.2.3 system registers system registers consist of four 32-bit registers: high and low multiply and accumulate registers (mach and macl), the procedure register (pr), and the program counter (pc). the multiply and accumulate registers store the results of multiply and multiply and accumulate operations. the procedure register stores the return address from the subroutine procedure. the program counter indicates the address of the program executing and controls the flow of the processing. macl pr pc mach 31 0 0 0 31 31 multiply and accumulate register high (mach) multiply and accumulate register low (macl) procedure register (pr): stores the return address for a subroutine procedure. program counter (pc): indicates the fourth byte after the current instruction. (1) multiply and accumulate register high, mach (32-bit, initial value = undefined) multiply and accumulate register low, macl (32-bit, initial value = undefined) mach/macl is used as the addition value in a mac instruction, and to store the operation result of a mac or mul instruction. (2) procedure register, pr (32-bit, initial value = undefined) pr stores the return address of a subroutine call using a bsr, bsrf, or jsr instruction, and is referenced by a subroutine return instruction (rts). (3) program counter, pc (32-bit, initial value = value of pc in vector table) the pc indicates the address of the instruction being executed.
section 2 programming model rev. 3.00 jul 08, 2005 page 7 of 484 rej09b0051-0300 2.2.4 floating-point registers figure 2.3 shows the floating-point registers. there are sixteen 32-bit floating-point registers, fpr0 to fpr15. these sixteen registers are referenced as fr0 to fr15 and dr0/2/4/6/8/10/12/14. the correspondence between fprn and the reference name is determined by the pr bit and sz bit in fpscr. see figure 2.3. (1) floating-point registers, fprn (16 registers) fpr0, fpr l, fpr2, fpr3, fpr4, fpr5, fpr6, fpr7, fpr8, fpr9, fpr10, fpr11, fpr12, fpr13, fpr14, fpr15 (2) single-precision floating-point registers, fri (16 registers) fr0 to fr15 are assigned to fpr0 to fpr15. (3) double-precision floating-point registers or single-precision floating-point register pairs, dri (8 registers) a dr register is composed of two fr registers. dr0 = (fpr0, fpr1), dr2 = (fpr2, fpr3 ), dr4 = (fpr4, fpr5), dr6 = (fpr6, fpr7), dr8 = (fpr8, fpr9), dr10 = (fpr10, fpr11), dr12 = (fpr12, fpr13), dr14 = (fpr14, fpr15)
section 2 programming model rev. 3.00 jul 08, 2005 page 8 of 484 rej09b0051-0300 fpr0 fpr1 fpr2 fpr3 fpr4 fpr5 fpr6 fpr7 fpr8 fpr9 fpr10 fpr11 fpr12 fpr13 fpr14 fpr15 fr0 fr1 fr2 fr3 fr4 fr5 fr6 fr7 fr8 fr9 fr10 fr11 fr12 fr13 fr14 fr15 dr0 dr2 dr4 dr6 dr8 dr10 dr12 dr14 in case of transfer instruction: in case of arithmetic/logical instruction: fpscr.sz = 0 fpscr.pr = 0 fpscr.sz = 1 fpscr.pr = 1 reference name register name figure 2.3 floating-point registers programming note: the values of fpr0 to fpr15 are undefined after a reset. 2.2.5 floating-point system registers (1) floating-point communication register, fpul (32-bit, initial value = undefined) data transfers between an fpu register and cpu register are performed via fpul. (2) floating-point status/control register, fpscr (32-bit, initial value = h'0004 0001) 31 23 22 21 20 19 18 17 12 11 7 6 2 1 0 ? qis ? sz pr dn cause enable flag rm
section 2 programming model rev. 3.00 jul 08, 2005 page 9 of 484 rej09b0051-0300 qis: snan is treated as qnan or . valid only when the v bit in the enable field of fpscr is set to 1. ? qis = 0: processed as qnan or . ? qis = 1: exception generated (processed same as snan). sz: transfer size mode ? sz = 0: the data size of an fmov instruction is 32 bits. ? sz = 1: the data size of an fmov instruction is a 32-bit pair (64 bits). pr: precision mode ? pr = 0: floating-point instructions are executed as single-precision operations. ? pr = 1: floating-point instructions are executed as double-precision operations (the result of an instruction for which double-precision is not supported is undefined). dn: denormalization mode (always 1) ? dn = 1: a denormalized number is treated as zero. cause: fpu exception cause field enable: fpu exception enable field flag: fpu exception flag field fpu error (e) invalid operation (v) division by zero (z) overflow (o) underflow (u) inexact exception (i) cause fpu exception cause field bit 17 bit 16 bit 15 bit 14 bit 13 bit 12 enable fpu exception enable field none bit 11 bit 10 bit 9 bit 8 bit 7 flag fpu exception flag field none bit 6 bit 5 bit 4 bit 3 bit 2 when an fpu operation instruction is executed, the fpu exception cause field is initially set to 0. when an fpu exception next occurs, the corresponding bit in the fpu exception cause field and fpu exception flag field is set to 1. the fpu exception flag field retains the status of an exception generated after that field was last cleared.
section 2 programming model rev. 3.00 jul 08, 2005 page 10 of 484 rej09b0051-0300 rm: rounding mode rm = 00: round to nearest rm = 01: round to zero rm = 10: reserved rm = 11: reserved bits 21, 23 to 31: reserved note: the SH-2A does not generate an fpu error. 2.2.6 register banks for the nineteen 32-bit registers comprising general registers r0 to r14, control register gbr, and system registers mach, macl, and pr, high-speed register saving and restoration can be carried out using a register bank. saving to the bank is performed automatically after the cpu accepts an interrupt that uses a register bank. restoration from the bank is executed by issuing a resbank instruction in an interrupt service routine. for details, refer to section 7, register banks. 2.2.7 register initial values table 2.1 initial values of registers classification register initial value general registers r0?r14 r15(sp) undefined sp value in the program address table control registers sr bits i3?i0 are 1111 (h'f), bo, cs are 0, reserved bits are 0, and other bits are undefined gbr, tbr undefined vbr h'00000000 system registers mach, macl, pr undefined pc value of the program counter in the vector address table floating-point registers frr0?frr15 undefined floating-point system registers fpul undefined fpscr h'00040001
section 2 programming model rev. 3.00 jul 08, 2005 page 11 of 484 rej09b0051-0300 2.3 data formats 2.3.1 data format in registers register operands are always longwords (32 bits). when data in memory is loaded to a register and the memory operand is only a byte (8 bits) or a word (16 bits), it is sign-extended into a longword when stored into a register. 31 0 longword 2.3.2 data formats in memory byte, word, and longword data formats are used. memory can be accessed in 8-bit bytes, 16-bit words, or 32-bit longwords. a memory operand of fewer than 32 bits is stored in a register in sign-extended or zero-extended form. a word operand should be accessed starting from a word boundary (2-byte even address: address 2n), and a longword operand from a longword boundary (4-byte even address: address 4n). if this rule is not observed, an address error will occur. a byte operand can be accessed from any address. only big-endian byte order can be selected for the data format. data formats in memory are shown in figure 2.4. 31 0 15 23 7 byte byte byte byte word word a ddress 2n a ddress 4n longword address m address m + 2 address m + 1 address m + 3 big-endian figure 2.4 data format in memory
section 2 programming model rev. 3.00 jul 08, 2005 page 12 of 484 rej09b0051-0300 2.3.3 immediate data format byte immediate data is located in an instruction code. immediate data accessed by the mov, add, and cmp/eq instructions is sign-extended and is handled in registers as longword data. immediate data accessed by the tst, and, or, and xor instructions is zero-extended and is handled as longword data. consequently, and instructions with immediate data always clear the upper 24 bits of the destination register. 20-bit immediate data is stored in the code of a movi20 or movi20s 32-bit transfer instruction. the movi20 instruction stores immediate data in the destination register in sign-extended form. the movi20s instruction shifts immediate data by 8 bits in the upper direction, and stores it in the destination register in sign-extended form. word or longword immediate data is not located in the instruction code but rather is stored in a memory table. the memory table is accessed by a immediate data transfer instruction (mov) using the pc relative addressing mode with displacement. specific examples are given in 4.1, (10) immediate data in section 4, instruction features.
section 2 programming model rev. 3.00 jul 08, 2005 page 13 of 484 rej09b0051-0300 2.4 processing states the cpu has five processing states: the reset state, exception handling state, bus-released state, program execution state, and power-down state. figure 2.5 shows the state transitions. reset release power-on reset state manual reset state program execution state bus-released state exception-handling state interrupt or dma address error nmi or irq interrupt end of exception handling bus request exception handling request bus request bus request cleared bus request cleared sleep instruction with stby bit cleared sleep instruction with stby bit set power-on reset from any state manual reset from any state reset state power-down state standby input from any state bus request bus request cleared software standby mode sleep mode hardware standby mode figure 2.5 processing state transitions
section 2 programming model rev. 3.00 jul 08, 2005 page 14 of 484 rej09b0051-0300 (1) reset state in this state, the cpu is reset. there are two kinds of reset, power-on and manual. see the hardware manual for details. (2) exception handling state the exception handling state is a transient state that occurs when the cpu alters the normal programming flow due to a reset, interrupt, or other exception handling source. in the case of a reset, the cpu fetches the execution start address as the initial value of the program counter (pc) from the exception vector table, and the initial value of the stack pointer (sp), stores these values, branches to the start address, and begins program execution at that address. in the case of an interrupt, etc., the cpu references the sp and saves the pc and status register (sr) in the stack area. it fetches the start address of the exception service routine from the exception vector table, branches to that address, and begins program execution. subsequently, the processing state is the program execution state. (3) program execution state in the program execution state the cpu executes program instructions in the normal sequence. (4) power-down state in the power-down state the cpu stops operating to conserve power. sleep mode or software standby mode is entered by executing a sleep instruction. if hardware standby input is received, the cpu enters the hardware standby mode. (5) bus-released state in the bus-released state, the cpu releases the bus to a device that has requested it. note: for information on the processing states, please refer to the hardware manual for the product in question.
section 3 exception handling rev. 3.00 jul 08, 2005 page 15 of 484 rej09b0051-0300 section 3 exception handling 3.1 overview 3.1.1 exception handling types and priority as table 3.1 indicates, exception handling may be caused by a reset, address error, ram error, register bank error, interrupt, or instruction. exception handling is prioritized as shown in table 3.1. if two or more exceptions occur simultaneously, they are accepted and processed in order of priority.
section 3 exception handling rev. 3.00 jul 08, 2005 page 16 of 484 rej09b0051-0300 table 3.1 exception types and priority exception handling priority power-on reset high reset manual reset cpu address error address errors dmac address error ram errors ram error fpu exception integer division exception (division by zero) instructions integer division exception (overflow) bank underflow register bank errors bank overflow nmi user break h-udi external interrupt (irq) interrupts on-chip peripheral modules trap instruction (trapa instruction) general illegal instruction (undefined code) instructions slot illegal instruction (undefined code (fpu instruction or fpu- related cpu instruction in module standby status including fpu or in product with no fpu, or register bank-related instruction * 2 in product with no register bank) located immediately after delayed branch instruction * 1 , instruction that modifies pc * 3 , 32-bit instruction * 4 , resbank instruction, divs instruction, or divu instruction) low notes: 1. delayed branch instructions: jmp, jsr, bra, bsr, rts, rte, bf/s, bt/s, bsrf, braf 2. register bank-related instructions: resbank, ldbank, stbank 3. instructions that modify pc: jmp, jsr, bra, bsr, rts, rte, bt, bf, trapa, bf/s, bt/s, bsrf, braf, jsr/n, rtv/n 4. 32-bit instructions: band.b, bandnot.b, bclr.b, bld.b, bldnot.b, bor.b, bornot.b, bset.b, bst.b, bxor.b, fmov.s @disp12, fmov.d @disp12, mov.b @disp12, mov.w @disp12, mov.l @disp12, movi20, movi20s, movu.b, movu.w
section 3 exception handling rev. 3.00 jul 08, 2005 page 17 of 484 rej09b0051-0300 3.1.2 exception handling operation table 3.2 shows the timing of detection and the start of exception handling for each exception source. table 3.2 timing of exception source detection and start of exception handling exception handling exception source detection and start of exception handling power-on reset started by detection of power-on reset condition reset manual reset started by detection of manual reset condition address error ram error interrupt detected when instruction is decoded; exception handling is started after completion of currently executing instruction register bank error bank underflow started upon attempted execution of resbank instruction when save has not been performed to register bank bank overflow started when save has already been performed to all register bank areas when acceptance of register overflow exception has been set by interrupt controller, and interrupt that uses register bank is generated and accepted by cpu instruction trap instruction started by execution of trapa instruction general illegal instruction started when undefined code (fpu instruction or fpu-related cpu instruction in module standby status including fpu or in product with no fpu, or register bank-related instruction in product with no register bank) not immediately following delayed branch instruction (delay slot) is decoded slot illegal instruction started when undefined code (fpu instruction or fpu-related cpu instruction in module standby status including fpu or in product with no fpu, or register bank-related instruction in product with no register bank) not immediately following delayed branch instruction (delay slot), instruction that modifies pc, 32-bit instruction, resbank instruction, divs instruction, or divu instruction is decoded integer division instruction started upon detection of division-by-zero exception or overflow exception caused by dividing negative maximum value (h?80000000) by ?1 floating-point operation instruction started by floating-point operation instruction invalid operation exception (stipulated by ieee754), or overflow, underflow, or imprecision interrupt. also started when qnan or is input to a floating-point operation instruction source
section 3 exception handling rev. 3.00 jul 08, 2005 page 18 of 484 rej09b0051-0300 when exception handling is initiated, the cpu operates as follows. (1) reset exception handling the initial values of the program counter (pc) and stack pointer (sp) are fetched from the exception vector table (addresses h'00000000 and h'00000004 in the case of a power-on reset, and addresses h'00000008 and h'0000000c in the case of a manual reset). see section 3.1.3, exception vector table, for details of the exception vector table. next, the vector base register is cleared to h'00000000, the interrupt mask bits (i3 to i0) in the status register (sr) are set to (h'f) (1111), and the bo and cs bits are initialized to 0. the bn bit in ibnr of intc is also initialized to 0. in addition, in products with an fpu, fpscr is initialized to h'00040001. program execution starts from the pc address fetched from the exception vector table. (2) address error, ram error, register bank error, interrupt, or instruction exception handling sr and pc are saved on the stack indicated by r15. in interrupt exception handling other than nmi and ubc, when register bank use has been set, general registers r0 to r14, control register gbr, system registers mach, macl, and pr, and the vector table address offset of the interrupt exception handling to be executed, are saved to the register bank. in the case of exception handling due to an address error, ram error, register bank error, nmi interrupt or ubc interrupt, saving to a register bank is not performed. also, when saving is performed to all register banks, automatic saving to the stack is performed instead of register bank saving. in this case, an interrupt controller setting must have been made for register bank overflow exceptions not to be accepted. if a setting has been made for register bank overflow exceptions to be accepted, a register bank overflow exception will be generated. in the case of interrupt exception handling, the interrupt priority level is written to the interrupt mask bits (i3 to i0) in sr. in address error, ram error, and instruction exception handling, bits i3 to i0 are not affected. next, the start address is fetched from the exception vector table and program execution is started from that address. 3.1.3 exception vector table before exception handling is executed, the exception vector table must have been set up in memory. the exception vector table holds the start addresses of the exception service routines (the reset exception handling table holds the initial values of pc and sp). a different vector number and vector table address offset are assigned to each exception source. the vector table address is calculated from the corresponding vector number and vector table address offset. in exception handling, the start address of the exception service routine is fetched from the exception vector table entry indicated by this vector table address.
section 3 exception handling rev. 3.00 jul 08, 2005 page 19 of 484 rej09b0051-0300 the vector numbers and vector table address offsets are shown in table 3.3, and the method of calculating the vector table address in table 3.4. table 3.3 exception vector table exception source vector number vector table address offset power-on reset pc 0 h'00000000 to h'00000003 sp 1 h'00000004 to h'00000007 manual reset pc 2 h'00000008 to h'0000000b sp 3 h'0000000c to h'0000000f general illegal instruction 4 h'00000010 to h'00000013 ram error 5 h'00000014 to h'00000017 slot illegal instruction 6 h'00000018 to h'0000001b (reserved for system) 7 h'0000001c to h'0000001f 8 h'00000020 to h'00000023 cpu address error 9 h'00000024 to h'00000027 dmac address error 10 h'00000028 to h'0000002b interrupt nmi 11 h'0000002c to h'0000002f user break 12 h'00000030 to h'00000033 fpu exception 13 h'00000034 to h'00000037 h-udi 14 h'00000038to h'0000003b bank overflow 15 h'0000003c to h'0000003f bank underflow 16 h'00000040 to h'00000043 integer division exception (division by zero) 17 h'00000044 to h'00000047 integer division exception (overflow) 18 h'00000048 to h'0000004b (reserved for system) 19 ? 31 h'0000004c to h'0000004f ? h'0000007c to h'0000007f trap instruction (user vector) 32 ? 63 h'00000080 to h'00000083 ? h'000000fc to h'000000ff external interrupt (irq), on-chip peripheral module * 64 ? 511 h'00000100 to h'00000103 ? h'000007fc to h'000007ff note: * for the vector numbers and address offsets of external interrupts and on-chip peripheral module interrupts, see ?internal module interrupt exception handling vectors and priority order? in the interrupt controller section of the hardware manual.
section 3 exception handling rev. 3.00 jul 08, 2005 page 20 of 484 rej09b0051-0300 table 3.4 exception vector table address calculation exception source vector table address calculation reset vector table address = (vector table address offset) = (vector number) 4 address error, ram error, register bank error, interrupt, instruction vector table address = vbr + (vector table address offset) = vbr + (vector number) 4 note: vbr: vector base register vector table address offset: see table 3.3. vector number: see table 3.3. 3.2 resets 3.2.1 types of reset a reset is the highest-priority exception handling source. there are two types of reset: a power-on reset and a manual reset. the cpu state is initialized by both a power-on reset and a manual reset. the fpu state is initialized by a power-on reset, but not by a manual reset. refer to the hardware manual of the relevant product for information on the states of on-chip peripheral modules, the pfc, and i/o ports. 3.2.2 power-on reset when a power-on reset condition is detected, the chip enters the power-on reset state. see ?power-on reset? in the exception handling section of the hardware manual for the relevant product for details of power-on reset conditions. when the power-on reset state is released, power-on reset exception handling is started. cpu operations are as follows. 1. the initial value of the program counter (pc) (i.e. the execution start address) is fetched from the exception vector table. 2. the initial value of the stack pointer (sp) is fetched from the exception vector table. 3. the vector base register (vbr) is cleared to h'00000000, the interrupt mask bits (i3 to i0) in the status register (sr) are set to (h'f) (1111), and the bo and cs bits are initialized to 0. the bn bit in ibnr of intc is also initialized to 0. in addition, in products with an fpu, fpscr is initialized to h'00040001.
section 3 exception handling rev. 3.00 jul 08, 2005 page 21 of 484 rej09b0051-0300 4. the values fetched from the exception vector table are set in the program counter (pc) and stack pointer (sp), and program execution is started. power-on reset processing must always be executed when the system is powered on. 3.2.3 manual reset when a manual reset condition is detected, the chip enters the manual reset state. see ?manual reset? in the exception handling section of the hardware manual for the relevant product for details of manual reset conditions. when the manual reset state is released, manual reset exception handling is started. cpu operations are as follows. 1. the initial value of the program counter (pc) (i.e. the execution start address) is fetched from the exception vector table. 2. the initial value of the stack pointer (sp) is fetched from the exception vector table. 3. the vector base register (vbr) is cleared to h'00000000, the interrupt mask bits (i3 to i0) in the status register (sr) are set to (h'f) (1111), and the bo and cs bits are initialized to 0. the bn bit in ibnr of intc is also initialized to 0. 4. the values fetched from the exception vector table are set in the program counter (pc) and stack pointer (sp), and program execution is started. when a manual reset occurs, the bus cycle is held. if a manual reset occurs while the bus is released or during a dmac burst transfer, manual reset exception handling is held pending until the cpu acquires the bus. however, if the interval from occurrence of a manual reset until the end of a bus cycle exceeds a given number of cycles, the internal manual reset source is not held pending but is ignored, and manual reset exception handling is not performed. see ?manual reset? in the exception handling section of the hardware manual for the relevant product for details. a manual reset initializes the cpu and the bn bit in ibnr of the intc. the fpu and other modules are not initialized.
section 3 exception handling rev. 3.00 jul 08, 2005 page 22 of 484 rej09b0051-0300 3.3 address errors 3.3.1 address error sources address errors occur in instruction fetches and data read/write accesses, as shown in table 3.5. table 3.5 bus cycles and address errors bus cycle type bus master bus cycle operation address error occurrence instruction fetched from even address no error (normal) instruction fetch cpu instruction fetched from odd address address error instruction fetched from other than on-chip peripheral module space * no error (normal) instruction fetched from on-chip peripheral module space * address error instruction fetched from external memory space in single-chip mode address error word data accessed from even address no error (normal) data read/write cpu or dmac word data accessed from odd address address error longword data accessed from longword boundary no error (normal) longword data accessed from other than longword boundary address error double longword data accessed from double longword boundary no error (normal) double longword data accessed from other than double longword boundary address error word data or byte data accessed in on-chip peripheral module space * no error (normal) longword data accessed in 16-bit on-chip peripheral module space * no error (normal) longword data accessed in 8-bit on-chip peripheral module space * no error (normal) external memory space accessed in single- chip mode address error note: * for details of the on-chip peripheral module space, see the bus state controller section of the hardware manual for the relevant product.
section 3 exception handling rev. 3.00 jul 08, 2005 page 23 of 484 rej09b0051-0300 3.3.2 address error exception handling when an address error occurs, address error exception handling is started after the end of the bus cycle in which the address error occurred and completion of the currently executing instruction. cpu operations are as follows. 1. the start address of the exception service routine corresponding to the address error is fetched from the exception handling vector table. 2. the status register (sr) is saved on the stack. 3. the program counter (pc) is saved on the stack. the saved pc value is the start address of the instruction following the last instruction executed. 4. execution jumps to the address fetched from the exception handling vector table and program execution commences. the jump is not a delayed branch. 3.4 ram errors 3.4.1 ram error sources a ram error occurs in the event of a software error in an on-chip ram read access. for details, see ?ram errors? in the exception handling section of the hardware manual for the relevant product. 3.4.2 ram error exception handling when a ram error occurs, ram error exception handling is started after the end of the bus cycle in which the error occurred and completion of the currently executing instruction. cpu operations are as follows. 1. the start address of the exception service routine corresponding to the ram error is fetched from the exception handling vector table. 2. the status register (sr) is saved on the stack. 3. the program counter (pc) is saved on the stack. the saved pc value is the start address of the instruction following the last instruction executed. 4. execution jumps to the address fetched from the exception handling vector table and program execution commences. the jump is not a delayed branch.
section 3 exception handling rev. 3.00 jul 08, 2005 page 24 of 484 rej09b0051-0300 3.5 register bank errors 3.5.1 register bank error sources (1) bank overflow when a save has already been performed to all register bank areas when acceptance of register overflow exception has been set by interrupt controller, and an interrupt that uses a register bank is generated and is accepted by the cpu (2) bank underflow when an attempt is made to execute a resbank instruction when a save has not been performed to a register bank 3.5.2 register bank error exception handling register bank error exception handling is started when a register bank error occurs. cpu operations are as follows. 1. the start address of the exception service routine corresponding to the register bank error is fetched from the exception handling vector table. 2. the status register (sr) is saved on the stack. 3. the program counter (pc) is saved on the stack. the saved pc value is the start address of the instruction following the last instruction executed, in the case of a bank overflow, or the start address of the executed resbank instruction, in the case of an underflow. to prevent multiple interrupts when a bank overflow occurs, the level of the interrupt that is the source of the bank overflow is written to the interrupt mask level bits (i3 to i0) in the status register (sr). 4. execution jumps to the address fetched from the exception handling vector table and program execution commences. the jump is not a delayed branch.
section 3 exception handling rev. 3.00 jul 08, 2005 page 25 of 484 rej09b0051-0300 3.6 interrupts 3.6.1 interrupt sources interrupt exception handling can be initiated by an nmi, a user break, the h-udi, an external interrupt, or an on-chip peripheral module, as shown in table 3.6. table 3.6 interrupt sources type request source number of sources nmi nmi pin (external input) 1 user break user break controller 1 h-udi user debug interface 1 external interrupt (irq), on-chip peripheral module external interrupt pin, on-chip peripheral module see note each interrupt source is assigned a different vector number and vector table offset. for details of vector numbers and vector table address offsets, see ?interrupt exception vectors and priority? in the interrupt controller section of the hardware manual for the relevant product. note: for details and numbers of external interrupts (irq) and on-chip peripheral module request sources, see ?interrupt sources? in the interrupt controller section of the hardware manual for the relevant product. 3.6.2 interrupt priority interrupt sources are assigned priority levels. if a number of interrupts occur simultaneously (multiple interruption), the priority order is determined by the interrupt controller (intc) and exception handling is initiated accordingly. interrupt source priority levels are expressed as values from 0 to 16, with 0 representing the lowest priority level and 16 the highest. the nmi interrupt is the highest-priority interrupt at level 16; it cannot be masked and is always accepted. the user break interrupt and h-udi are assigned priority level 15. the priority level of irq interrupts and on-chip peripheral module interrupts can be set as desired in the interrupt priority level setting registers of the intc (see table 3.7). priority levels 0 to 15, but not 16, can be set. for details of the interrupt priority level setting registers, see the interrupt controller section of the hardware manual for the relevant product.
section 3 exception handling rev. 3.00 jul 08, 2005 page 26 of 484 rej09b0051-0300 table 3.7 interrupt priority levels type priority level notes nmi 16 fixed priority level, not maskable user break 15 fixed priority level h-udi 15 fixed priority level external interrupt (irq), on-chip peripheral module 0 to 15 can be set in interrupt priority level setting register 3.6.3 interrupt exception handling when an interrupt occurs, its priority is determined by the interrupt controller (intc). nmi is always accepted, but other interrupts are only accepted if their priority level is higher than the priority level set in the interrupt mask bits (i3 to i0) in the status register (sr). when an interrupt is accepted, interrupt exception handling is started. in interrupt exception handling, the cpu saves sr and the program counter (pc) on the stack. in interrupt exception handling other than nmi, ubc, when register bank use has been set, general registers r0 to r14, control register gbr, system registers mach, macl, and pr, and the vector table address offset of the interrupt exception handling to be executed, are saved to the register bank. in the case of exception handling due to an address error, ram error, register bank error, nmi interrupt, ubc interrupt, or instruction, saving to a register bank is not performed. also, when saving is performed to all register banks, automatic saving to the stack is performed instead of register bank saving. in this case, an interrupt controller setting must have been made for register bank overflow exceptions not to be accepted. if a setting has been made for register bank overflow exceptions to be accepted, a register bank overflow exception will be generated. the interrupt priority level of the accepted interrupt is then written to bits i3 to i0 in sr. in the case of nmi, however, although its priority level is 16, h'f (level 15) is written to bits i3 to i0. next, the cpu fetches the exception service routine start address from the exception vector table entry corresponding to the accepted interrupt, jumps to that address, and starts executing the exception service routine. for details of interrupt exception handling, see ?operation? in the interrupt controller section of the hardware manual for the relevant product.
section 3 exception handling rev. 3.00 jul 08, 2005 page 27 of 484 rej09b0051-0300 3.7 instruction exceptions 3.7.1 types of instruction exception there are five kinds of instruction that can initiate exception handling: the trap instruction, slot illegal instructions, general illegal instructions, integer division instructions, and floating-point operation instructions. these are summarized in table 3.8. table 3.8 instruction exception types type source instruction notes trap instruction trapa slot illegal instruction undefined code (fpu instruction or fpu-related cpu instruction in module standby status including fpu or in product with no fpu, or register bank- related instruction in product with no register bank) located immediately after delayed branch instruction (in delay slot), instruction that modifies pc, 32- bit instruction, resbank instruction, divs instruction, or divu instruction delayed branch instructions: jmp, jsr, bra, bsr, rts, rte, bf/s, bt/s, bsrf, braf register bank-related instructions: resbank, ldbank, stbank instructions that modify pc: jmp, jsr, bra, bsr, rts, rte, bt, bf, trapa, bf/s, bt/s, bsrf, braf, jsr/n, rtv/n 32-bit instructions: band.b, bandnot.b, bclr.b, bld.b, bldnot.b, bor.b, bornot.b, bset.b, bst.b, bxor.b, fmov.s @disp12, fmov.d @disp12, mov.b @disp12, mov.w @disp12, mov.l @disp12, movi20, movi20s, movu.b, movu.w general illegal instruction undefined code (fpu instruction, fpu- related cpu instruction, or register bank-related instruction in module standby status including fpu or in product with no fpu) not in delay slot division by zero divu, divs integer division exception negative maximum value (-1) divs floating-point operation instruction instruction causing invalid operation defined by ieee754 standard or division-by-zero exception, instruction causing overflow, underflow, or inexact exception fadd, fsub, fmul, fdiv, fmac, fcmp/eq, fcmp/gt, float, ftrc, fcnvds, fcnvsd, fsqrt
section 3 exception handling rev. 3.00 jul 08, 2005 page 28 of 484 rej09b0051-0300 3.7.2 trap instruction when a trapa instruction is executed, trap instruction exception handling is started. the cpu operates as follows. 1. the start address of the exception service routine corresponding to the vector number specified by the trapa instruction is fetched from the exception handling vector table. 2. the status register (sr) is saved on the stack. 3. the program counter (pc) is saved on the stack. the saved pc value is the start address of the instruction following the trapa instruction. 4. execution jumps to the address fetched from the exception handling vector table and program execution commences. the jump is not a delayed branch. 3.7.3 slot illegal instructions an instruction located immediately after a delayed branch instruction is said to be located in the delay slot. if the instruction in the delay slot is undefined code, slot illegal instruction exception handling is started when that undefined code is decoded. also, if the instruction in the delay slot is one that modifies the program counter (pc), slot illegal instruction exception handling is started when that instruction is decoded. moreover, in the case of a product that does not have an fpu, or if the fpu is in the module standby state, a floating-point instruction or fpu-related instruction is treated as undefined code, and if located in a delay slot, will cause slot illegal instruction exception handling to be started when decoded. in addition, if the product that does not have a register bank, register bank-related instructions are treated as undefined code. if located in a delay slot, when decoded they will cause slot illegal instruction handling to be started. furthermore, if an instruction located in a delay slot is a 32-bit instruction, resbank instruction, divs instruction, or divu instruction, slot illegal instruction exception handling will be started when this instruction is decoded. cpu operations in slot illegal instruction exception handling are as follows. 1. the start address of the exception service routine is fetched from the exception handling vector table. 2. the status register (sr) is saved on the stack. 3. the program counter (pc) is saved on the stack. the saved pc value is the jump destination address of the delayed branch instruction immediately preceding an undefined code, instruction that overwrites the pc, 32-bit instruction, resbank instruction, divs instruction, or divu instruction. 4. execution jumps to the address fetched from the exception handling vector table and program execution commences. the jump is not a delayed branch.
section 3 exception handling rev. 3.00 jul 08, 2005 page 29 of 484 rej09b0051-0300 3.7.4 general illegal instructions when undefined code located other than immediately after a delayed branch instruction (in a delay slot) is decoded, general illegal instruction exception handling is started. also, in the case of a product that does not have an fpu, or if the fpu is in the module standby state, a floating-point instruction or fpu-related instruction is treated as undefined code, and if located other than immediately after a delayed branch instruction (in a delay slot), will cause general illegal instruction exception handling to be started when decoded. in addition, if the product that does not have a register bank, register bank-related instructions are treated as undefined code. if not located immediately after a delayed branch instruction (in a delay slot), when decoded they will cause slot illegal instruction handling to be started. the cpu follows the same procedure as in the case of slot illegal instruction exception handling, except that the pc value saved is the start address of the undefined code. 3.7.5 integer division instructions an integer division exception is generated if an integer division instruction executes division by zero, or if the result of integer division overflows. instructions that may cause a division-by-zero exception are divu and divs. the only instruction that may cause an overflow exception is divs, the exception being generated if the negative maximum value is divided by ?1. cpu operations in integer division exception handling are as follows. 1. the start address of the exception service routine corresponding to the integer division exception is fetched from the exception handling vector table. 2. the status register (sr) is saved on the stack. 3. the program counter (pc) is saved on the stack. the saved pc value is the start address of the integer division instruction that generated the exception. 4. execution jumps to the address fetched from the exception handling vector table and program execution commences. the jump is not a delayed branch. 3.7.6 floating-point operation instructions an fpu exception is generated when the v, z, o, u, or i bit in the enable field of the fpscr register is set. this indicates the occurrence of an invalid operation exception defined by the ieee754 standard, a division-by-zero exception, overflow (in the case of an instruction for which this is possible), underflow (in the case of an instruction for which this is possible), or an imprecision exception (in the case of an instruction for which this is possible). floating-point operation instructions that may cause an exception are as follows.
section 3 exception handling rev. 3.00 jul 08, 2005 page 30 of 484 rej09b0051-0300 fadd, fsub, fmul, fdiv, fmac, fcmp/eq, fcmp/gt, float, ftrc, fcnvds, fcnvsd, fsqrt an fpu exception is generated only when the corresponding enable bit is set. when the fpu detects an exception, fpu operation is halted and exception generation is reported to the cpu. when exception handling is started, cpu operations are as follows. 1. the start address of the exception service routine stored in vbr + h'00000034 is fetched from the exception handling vector table. 2. sr contents are saved on the stack. 3. pc is saved on the stack. the pc value saved is the start address of the instruction following the last instruction executed. 4. control branches to the address stored in vbr + h'00000034. the exception flag bits in fpscr are always updated regardless of whether or not an fpu exception has been accepted, and remain set until explicitly cleared by the user by means of an instruction. the fpscr source bits change each time an fpu instruction is executed. when the v bit in the enable field of the fpscr register is set and the qis bit in fpscr is also set, fpu exception handling is started when qnan or is input to a floating-point operation instruction source. 3.8 cases in which exceptions are not accepted there are cases, as shown in table 3.9, in which, if an address error, ram error, fpu exception, register bank error (overflow), or interrupt occurs immediately after a delayed branch instruction, the exception is not accepted immediately, but is held pending. in such cases, the exception will be accepted when an instruction for which exception acceptance is permitted is decoded. table 3.9 exception source occurrence immediately after delayed branch instruction exception source point of occurrence address error ram error fpu exception register bank error (overflow) interrupt immediately after a delayed branch instruction * notes: : not accepted * delayed branch instructions: jmp, jsr, bra, bsr, rts, rte, bf/s, bt/s, bsrf, braf
section 3 exception handling rev. 3.00 jul 08, 2005 page 31 of 484 rej09b0051-0300 3.9 stack status after exception handling table 3.10 shows the stack status after completion of exception handling. table 3.10 stack status after exception handling address of instruction following executed instruction (32 bits) sr sp (32 bits) address of instruction following executed instruction (32 bits) sr sp (32 bits) start address of relevant resbank instruction (32 bits) sr sp (32 bits) address of instruction following trapa instruction (32 bits) sr sp (32 bits) start address of general illegal instruction (32 bits) sr sp (32 bits) address of instruction following executed instruction (32 bits) sr sp (32 bits) address of instruction following executed instruction (32 bits) sr sp (32 bits) start address of relevant integer division instruction (32 bits) sr sp (32 bits) jump destination address of delayed branch instruction (32 bits) sr sp (32 bits) address of instruction following executed instruction (32 bits) sr sp (32 bits) address error ram error register bank error (underflow) trap instruction general illegal instruction interrupt register bank error (overflow) integer division instruction (division by zero, overflow) slot illegal instruction fpu exception stack status type stack status type
section 3 exception handling rev. 3.00 jul 08, 2005 page 32 of 484 rej09b0051-0300 3.10 usage notes 3.10.1 stack pointer (sp) value ensure that the stack pointer (sp) value is a multiple of 4. if it is not, an address error will be caused when the stack is accessed in exception handling. 3.10.2 vector base register (vbr) value ensure that the vector base register (vbr) value is a multiple of 4. if it is not, an address error will be caused when the vector is accessed in exception handling. 3.10.3 address errors occurring in address error exception handling stacking if the stack pointer (sp) value is not a multiple of 4, an address error will occur in exception handling (interrupt, etc.) stacking, and after the exception handling is completed, address error exception handling will be started. an address error will also occur in stacking in the address error exception handling, but this address error will not be accepted in order to prevent endless stacking due to address errors. this enables program control to be switched to the address error exception service routine, and error handling to be carried out. when an address error occurs in exception handling stacking, the stacking bus cycle (write) is executed. in sr and pc stacking, sp is decremented by 4 in each case, and therefore the sp value is not a multiple of 4 after stacking is completed. also, the address value output in stacking is the sp value, and the actual address at which the error occurred is output. in this case, the stacked write data is undefined.
section 4 instruction features rev. 3.00 jul 08, 2005 page 33 of 484 rej09b0051-0300 section 4 instruction features 4.1 risc-type instruction set all instructions are risc type. their features are detailed in this section. (1) 16-bit fixed-length instructions basic instructions have a fixed length of 16 bits, increasing program code efficiency. (2) addition of 32-bit fixed-length instructions the SH-2A/sh2a-fpu features the addition of 32-bit fixed-length instructions, improving performance and ease of use. (3) one instruction/cycle basic instructions can be executed in one cycle using the pipeline system. (4) data length longword is the standard data length for all operations. memory can be accessed in bytes, words, or longwords. byte or word data accessed from memory is sign-extended and calculated with longword data. immediate data is sign-extended for arithmetic operations or zero-extended for logic operations. it also is calculated with longword data. table 4.1 sign extension of word data SH-2A/sh2a-fpu cpu description example for other cpu mov.w @(disp,pc),r1 add r1,r0 ......... .data.w h'1234 data is sign-extended to 32 bits, and r1 becomes h'00001234. it is next operated upon by an add instruction. add.w #h'1234,r0 note: the address of the immediate data is accessed by @(disp, pc). (5) load-store architecture basic operations are executed between registers. for operations that involve memory access, data is loaded to the registers and executed (load-store architecture). instructions such as and that manipulate bits, however, are executed directly in memory.
section 4 instruction features rev. 3.00 jul 08, 2005 page 34 of 484 rej09b0051-0300 (6) delayed branching with the exception of some instructions, unconditional branch instructions, etc., are executed as delayed branches. with a delayed branch instruction, the branch is made after execution of the instruction immediately following the delayed branch instruction. this reduces disruption of the pipeline when a branch is made. in a delayed branch, the actual branch operation occurs after execution of the slot instruction. however, instruction execution for register updating, etc., excluding the branch operation, is performed in delayed branch instruction delay slot instruction order. for example, even though the contents of the register holding the branch destination address are changed in the delay slot, the branch destination address remains as the register contents prior to the change. table 4.2 delayed branch instructions SH-2A/sh2a-fpu cpu description example of other cpu bra trget add r1,r0 add is executed before branch to trget. add.w r1,r0 bra trget (7) addition of unconditional branch instructions with no delay slot the SH-2A/sh2a-fpu features the addition of unconditional branch instructions in which a delay slot instruction is not executed. this makes it possible to cut down on the number of unnecessary nop instructions, and so reduce the code size. (8) multiplication/accumulation operation 16bit 16bit 32-bit multiplication operations are executed in one to two cycles. 16bit 16bit + 64bit 64-bit multiplication/accumulation operations are executed in two to three cycles. 32bit 32bit 64-bit multiplication and 32bit 32bit + 64bit 64-bit multiplication/accumulation operations are executed in two to four cycles. (9) t bit the t bit in the status register changes according to the result of the comparison, and in turn is the condition (true/false) that determines if the program will branch. the number of instructions after t bit in the status register is kept to a minimum to improve the processing speed.
section 4 instruction features rev. 3.00 jul 08, 2005 page 35 of 484 rej09b0051-0300 table 4.3 t bit SH-2A/sh2a-fpu cpu description example for other cpu cmp/ge r1,r0 bt trget0 bf trget1 t bit is set when r0 r1. the program branches to trget0 when r0 r1 and to trget1 when r0 < r1. cmp.w r1,r0 bge trget0 blt trget1 add #?1,r0 cmp/eq #0,r0 bt trget t bit is not changed by add. t bit is set when r0 = 0. the program branches if r0 = 0. sub.w #1,r0 beq trget (10) immediate data byte immediate data is located in instruction code. word or longword immediate data is not input via instruction codes but is stored in a memory table. the memory table is accessed by an immediate data transfer instruction (mov) using the pc relative addressing mode with displacement. with the SH-2A/sh2a-fpu, immediate data of 17 to 28 bits can be located in an instruction code. however, for immediate data of 21 to 28 bits, an or instruction must be executed after a register transfer. table 4.4 referencing by means of immediate data type SH-2A/sh2a-fpu cpu example for other cpu 8-bit immediate mov #h'12,r0 mov.b #h'12,r0 16-bit immediate movi20 #h'1234, r0 mov.w #h'1234,r0 20-bit immediate movi20 #h'12345, r0 mov.l #h'12345,r0 28-bit immediate movi20s #h'12345, r0 or #h'67, r0 mov.l #h'1234567,r0 32-bit immediate mov.l @(disp,pc),r0 . . . . . . . . . . . .data.l h'12345678 mov.l #h'12345678,r0 note: immediate data is referenced by @(disp,pc).
section 4 instruction features rev. 3.00 jul 08, 2005 page 36 of 484 rej09b0051-0300 (11) absolute address when data is accessed by absolute address, the value already in the absolute address is placed in the memory table. loading the immediate data when the instruction is executed transfers that value to the register and the data is accessed in the indirect register addressing mode. with the SH-2A/sh2a-fpu, when data is referenced using an absolute address not exceeding 28 bits, it is also possible to transfer immediate data located in the instruction code to a register, and reference the data using register indirect addressing mode. however, when referencing data using an absolute address of 21 to 28 bits, an or instruction must be used after the register transfer. table 4.5 referencing by means of absolute address type SH-2A/sh2a-fpu cpu example for other cpu up to 20 bits movi20 #h'12345, r1 mov.b @r1, r0 mov.b @h'12345,r0 21 to 28 bits movi20s #h'12345, r1 or #h'67, r1 mov.b @r1, r0 mov.b @h'1234567,r0 29 bits or more mov.l @(disp,pc),r1 mov.b @r1,r0 . . . . . . . . . . .data.l h'12345678 mov.b @h'12345678,r0 (12) 16-bit/32-bit displacement when data is accessed by 16-bit or 32-bit displacement, the pre-existing displacement value is placed in the memory table. loading the immediate data when the instruction is executed transfers that value to the register and the data is accessed in the indirect indexed register addressing mode. table 4.6 displacement accessing type SH-2A/sh2a-fpu cpu example for other cpu 16-bit displacement mov.w @(disp,pc),r0 mov.w @(r0,r1),r2 .................. .data.w h'1234 mov.w @(h'1234,r1),r2
section 4 instruction features rev. 3.00 jul 08, 2005 page 37 of 484 rej09b0051-0300 4.2 addressing modes addressing modes effective address calculation by the cpu core are described below. table 4.7 addressing modes and effective addresses addressing mode instruction format effective addresses calculation formula direct register addressing rn the effective address is register rn. (the operand is the contents of register rn.) ? indirect register addressing @rn the effective address is the content of register rn. rn rn rn post- increment indirect register addressing @rn + the effective address is the content of register rn. a constant is added to the content of rn after the instruction is executed. 1 is added for a byte operation, 2 for a word operation, or 4 for a longword operation. rn rn 1/2/4 + rn + 1/2/4 rn (after the instruction is executed) byte: rn + 1 rn word: rn + 2 rn longword: rn + 4 rn pre- decrement indirect register addressing @?rn the effective address is the value obtained by subtracting a constant from rn. 1 is subtracted for a byte operation, 2 for a word operation, or 4 for a longword operation. rn 1/2/4 rn 1/2/4 rn 1/2/4 byte: rn ? 1 rn word: rn ? 2 rn longword: rn ? 4 rn (instruction executed with rn after calculation)
section 4 instruction features rev. 3.00 jul 08, 2005 page 38 of 484 rej09b0051-0300 addressing mode instruction format effective addresses calculation formula indirect register addressing with displace- ment @(disp:4, rn) the effective address is rn plus a 4-bit displacement (disp). the value of disp is zero-extended, and remains the same for a byte operation, is doubled for a word operation, or is quadrupled for a longword operation. rn 1/2/4 rn + disp 1/2/4 + disp (zero-extended) byte: rn + disp word: rn + disp 2 longword: rn + disp 4 @(disp:12, rn) effective address is register rn contents with 12-bit displacement disp added. disp is zero-extended. rn rn + disp + disp (zero-extended) byte: rn + disp word: rn + disp longword: rn + disp indirect indexed register addressing @(r0, rn) the effective address is the rn value plus r0. rn r0 rn + r0 + rn + r0 indirect gbr addressing with displace- ment @(disp:8, gbr) the effective address is the gbr value plus an 8-bit displacement (disp). the value of disp is zero- extended, and remains the same for a byte operation, is doubled for a word operation, or is quadrupled for a longword operation. gbr 1/2/4 gbr + disp 1/2/4 + disp (zero-extended) byte: gbr + disp word: gbr + disp 2 longword: gbr + disp 4
section 4 instruction features rev. 3.00 jul 08, 2005 page 39 of 484 rej09b0051-0300 addressing mode instruction format effective addresses calculation formula indirect indexed gbr addressing @(r0, gbr) the effective address is the gbr value plus r0. gbr r0 gbr + r0 + gbr + r0 tbr duplicate indirect with displacement @@(disp:8, tbr) effective address is register tbr contents with 8-bit displacement disp added. after disp is zero- extended, it is multiplied by 4. tbr 4 tbr + disp 4 (tbr + disp 4) + disp (zero-extended) (tbr + disp x 4) address contents pc relative addressing with displace- ment @(disp:8, pc) the effective address is the pc value plus an 8-bit displacement (disp). the value of disp is zero- extended, and disp is doubled for a word operation, or is quadrupled for a longword operation. for a longword operation, the lowest two bits of the pc are masked. pc h'fffffffc pc + disp 2 or pc&h'fffffffc + disp 4 + 2/4 x & (for longword) disp (zero-extended) word: pc + disp 2 longword: pc & h'fffffffc + disp 4
section 4 instruction features rev. 3.00 jul 08, 2005 page 40 of 484 rej09b0051-0300 addressing mode instruction format effective addresses calculation formula pc relative addressing disp:8 the effective address is the pc value sign-extended with an 8-bit displacement (disp), doubled, and added to the pc. pc 2 + disp (sign-extended) pc + disp 2 pc + disp 2 disp:12 the effective address is the pc value sign-extended with a 12-bit displacement (disp), doubled, and added to the pc. pc 2 + disp (sign-extended) pc + disp 2 pc + disp 2 rn the effective address is the register pc plus rn. pc r0 pc + r0 + pc + rn immediate addressing #imm:20 20-bit immediate data imm of movi20 instruction is sign-extended. 31 0 19 sign extension imm (20 bits) ? 20-bit immediate data imm of movi20s instruction is left-shifted 8 bits, upper part is sign-extended, and lower part is zero-padded. 31 0 27 8 sign extension imm (20 bits) 00000000 ?
section 4 instruction features rev. 3.00 jul 08, 2005 page 41 of 484 rej09b0051-0300 addressing mode instruction format effective addresses calculation formula immediate addressing #imm:8 the 8-bit immediate data (imm) for the tst, and, or, and xor instructions are zero-extended. ? #imm:8 the 8-bit immediate data (imm) for the mov, add, and cmp/eq instructions are sign-extended. ? #imm:8 immediate data (imm) for the trapa instruction is zero-extended and is quadrupled. ? #imm:3 3-bit immediate data imm of band, bor, bxor, bst, bld, bset, or bclr instruction indicates bit position. ? 4.3 instruction format the instruction format table, table 5.8, refers to the source operand and the destination operand. the meaning of the operand depends on the instruction code. the symbols are used as follows: xxxx: instruction code mmmm: source register nnnn: destination register iiii: immediate data dddd: displacement
section 4 instruction features rev. 3.00 jul 08, 2005 page 42 of 484 rej09b0051-0300 table 4.8 instruction formats instruction formats source operand destination operand example 0 format xxxx xxxx xxxx xxxx 15 0 DD nop D nnnn: register direct mov t rn n format xxxx xxxx xxxx nnnn 15 0 control register or system register nnnn: register direct sts mach,rn r0 (register direct) nnnn: register direct divu r0, rn control register or system register nnnn: register indirect with pre- decrement stc.l sr,@-rn mmmm: register direct r15 (register indirect with pre- decrement) movmu.l rm,@-r15 r15 (register indirect with post-increment) nnnn: register direct movmu.l @r15+,rn r0 (register direct) nnnn: register indirect with post- increment mov.l r0,@rn+ mmmm: register direct control register or system register ldc rm,sr m format xxxx mmmm xxxx xxxx 15 0 mmmm: register indirect with post- increment control register or system register ldc.l @rm+,sr mmmm: register indirect ? jmp @rm mmmm: register indirect with pre- decrement r0 (register direct) mov.l @-rm, r0 mmmm: pc- relative using rm ? braf rm
section 4 instruction features rev. 3.00 jul 08, 2005 page 43 of 484 rej09b0051-0300 instruction formats source operand destination operand example mmmm: direct register nnnn: direct register add rm,rn nm format nnnn xxxx xxxx 15 0 mmmm mmmm: direct register nnnn: indirect register mov.l rm,@rn mmmm: indirect post-increment register (multiply/ accumulate) nnnn * : indirect post-increment register (multiply/ accumulate) mach, macl mac.w @rm+,@rn+ mmmm: indirect post-increment register nnnn: direct register mov.l @rm+,rn mmmm: direct register nnnn: indirect pre- decrement register mov.l rm,@-rn mmmm: direct register nnnn: indirect indexed register mov.l rm,@(r0,rn) md format xxxx dddd 15 0 mmmm xxxx mmmmdddd: indirect register with displacement r0 (direct register) mov.b @(disp,rm),r0 nd4 format dddd nnnn xxxx 15 0 xxxx r0 (direct register) nnnndddd: indirect register with displacement mov.b r0,@(disp,rn) mmmm: direct register nnnndddd: indirect register with displacement mov.l rm,@(disp,rn) nmd format nnnn xxxx dddd 15 0 mmmm mmmmdddd: indirect register with displacement nnnn: direct register mov.l @(disp,rm),rn
section 4 instruction features rev. 3.00 jul 08, 2005 page 44 of 484 rej09b0051-0300 instruction formats source operand destination operand example mmmm: register direct nnnndddd: register indirect with displacement mov.l rm,@(disp12, rn) nmd12 format nnnn xxxx xxxx 32 16 mmmm dddd xxxx dddd 15 0 dddd mmmmdddd: register indirect with displacement nnnn: register direct mov.l @(disp12,rm), rn dddddddd: gbr indirect with displacement r0 (register direct) mov.l @(disp,gbr),r0 d format dddd xxxx 15 0 xxxx dddd r0 (register direct) dddddddd: gbr indirect with displacement mov.l r0,@(disp,gbr) dddddddd: pc- relative with displacement r0 (register direct) mova @(disp,pc),r0 dddddddd: tbr duplicate indirect with displacement ? jsr/n @@(disp8,tbr) dddddddd: pc- relative ? bf label d12 format dddd xxxx 15 0 dddd dddd dddddddddddd: pc relative ? bra label (label = disp + pc) nd8 format dddd nnnn xxxx 15 0 dddd dddddddd: pc relative with displacement nnnn: direct register mov.l @(disp,pc),rn iiiiiiii: immediate indirect indexed gbr and.b #imm,@(r0,gbr) i format i i i i xxxx 15 0 xxxx i i i i iiiiiiii: immediate r0 (direct register) and #imm,r0 iiiiiiii: immediate ? trapa #imm ni format nnnn i i i i xxxx 15 0 i i i i iiiiiiii: immediate nnnn: direct register add #imm,rn
section 4 instruction features rev. 3.00 jul 08, 2005 page 45 of 484 rej09b0051-0300 instruction formats source operand destination operand example ni3 format xxxx mmmm xxxx i i i 15 0 x nnnn: register direct iii: immediate ? bld #imm3,rn ? nnnn: register direct iii: immediate bst #imm3,rn ni20 format nnnn xxxx xxxx 32 16 i i i i i i i i i i i i i i i i 15 0 i i i i iiiiiiiiiiiiiiiiiiii: immediate nnnn: register direct movi20 #imm20,rn nnnnddddddddd ddd: register indirect with displacement iii: immediate ? bld.b #imm3,@(disp12,rn) nid format nnnn xxxx xxxx 32 16 xiii dddd xxxx dddd 15 0 dddd ? nnnnddddddddddd d: register indirect with displacement iii: immediate bst.b #imm3,@(disp12,rn) note: * in multiply/accumulate instructions, nnnn is the source register.
section 4 instruction features rev. 3.00 jul 08, 2005 page 46 of 484 rej09b0051-0300
section 5 instruction set rev. 3.00 jul 08, 2005 page 47 of 484 rej09b0051-0300 section 5 instruction set 5.1 instruction set by classification table 5.1 shows instruction by classification. table 5.1 classification of instruction classification instruction type op code function number of instructions data transfer instructions 13 mov data transfer immediate data transfer peripheral module data transfer structure data transfer reverse stack transfer 62 mova execution address transfer movi20 20-bit immediate data transfer movi20s 20-bit immediate data transfer 8-bit left-shift movml r0-rn register save/restore movmu rn-r14, pr register save/restore movrt t bit inversion and transfer to rn movt t bit transfer movu unsigned data transfer nott t bit inversion pref prefetch to operand cache swap upper/lower swap xtrct extraction of middle of linked registers
section 5 instruction set rev. 3.00 jul 08, 2005 page 48 of 484 rej09b0051-0300 classification instruction type op code function number of instructions 26 add binary addition 40 addc binary addition with carry arithmetic operation instructions addv binary addition with overflow cmp/cond comparison clips signed saturation value comparison clipu unsigned saturation value comparison divs signed division (32 32) divu unsigned division (32 32) div1 1-step division div0s signed 1-step division initialization div0u unsigned 1-step division initialization dmuls signed double-precision multiplication dmulu unsigned double-precision multiplication dt decrement and test exts sign extension extu zero extension mac multiply and accumulate, double- precision multiply and accumulate mul double-precision multiplication mulr rn result storage signed multiplication muls signed multiplication mulu unsigned multiplication neg sign inversion negc sign inversion with borrow sub binary subtraction subc binary subtraction with borrow subv binary subtraction with underflow
section 5 instruction set rev. 3.00 jul 08, 2005 page 49 of 484 rej09b0051-0300 classification instruction type op code function number of instructions 6 and logical and 14 logic operation instructions not bit inversion or logical or tas memory test and bit setting tst logical and t bit setting xor exclusive logical or shift instructions 12 rotl 1-bit left rotation 1 6 rotr 1-bit right rotation rotcl 1-bit left rotation with t bit rotcr 1-bit right rotation with t bit shad dynamic arithmetic shift shal arithmetic 1-bit left shift shar arithmetic 1-bit right shift shld dynamic logical shift shll logical 1-bit left shift shlln logical n-bit left shift shlr logical 1-bit right shift shlrn logical n-bit right shift
section 5 instruction set rev. 3.00 jul 08, 2005 page 50 of 484 rej09b0051-0300 classification instruction type op code function number of instructions branch instructions 10 bf conditional branch, delayed conditional branch (branches if t = 0) 15 bt conditional branch, delayed conditional branch (branches if t = 1) bra unconditional delayed branch braf unconditional delayed branch bsr delayed branch to subroutine procedure bsrf delayed branch to subroutine procedure jmp unconditional delayed branch jsr branch to subroutine procedure, delayed branch to subroutine procedure rts return from subroutine procedure, delayed return from subroutine procedure rtv/n return from subroutine procedure with rm r0 transfer 14 clrt t bit clear 36 system control instructions clrmac mac register clear ldbank register restoration from specified register bank entry ldc load into control register lds load into system register nop no operation resbank register restoration from register bank rte return from exception handling sett t bit setting sleep transition to power-down state stbank register save to specified register bank entry stc store from control register sts store from system register trapa trap exception handling
section 5 instruction set rev. 3.00 jul 08, 2005 page 51 of 484 rej09b0051-0300 classification instruction type op code function number of instructions 19 fabs floating-point absolute value 48 floating-point instructions fadd floating-point addition fcmp floating-point comparison fcnvds conversion from double-precision to single-precision fcnvsd conversion from single-precision to double-precision fdiv floating-point division fldi0 floating-point load immediate 0 fldi1 floating-point load immediate 1 flds floating-point load into system register fpul float conversion from integer to floating- point fmac floating-point multiply and accumulate operation fmov floating-point data transfer fmul floating-point multiplication fneg floating-point sign inversion fschg sz bit inversion fsqrt floating-point square root fsts floating-point store from system register fpul fsub floating-point subtraction ftrc floating-point conversion with rounding to integer 2 lds load into floating-point system register 8 fpu-related cpu instructions sts store from floating-point system register
section 5 instruction set rev. 3.00 jul 08, 2005 page 52 of 484 rej09b0051-0300 classification instruction type op code function number of instructions band bit and bclr bit clear bld bit load bor bit or bset bit setting bst bit store bxor bit exclusive or bandnot bit not and bornot bit not or bit manipulation instructions 10 bldnot bit not load 14 total 112 253
section 5 instruction set rev. 3.00 jul 08, 2005 page 53 of 484 rej09b0051-0300 table 5.2 shows the format used in tables 5.3 to 5.8, which list instruction codes, operation, and execution states in order by classification. table 5.2 instruction code format item format explanation instruction rm: source register rn: destination register imm: immediate data disp: displacement * 1 instruction code msb ? lsb mmmm: source register nnnn: destination register 0000: r0 0001: r1 ? ? ? 1111: r15 iiii: immediate data dddd: displacement operation , direction of transfer (xx) memory operand m/q/t flag bits in the sr & logical and of each bit | logical or of each bit ^ exclusive or of each bit ~ logical not of each bit <>n n-bit right shift execution cycles ? value when no wait states are inserted * 2 t bit ? value of t bit after instruction is executed. an em-dash (?) in the column means no change. notes: 1. depending on the operand size, displacement is scaled 1, 2, or 4. for details, see section 5, instruction descriptions. 2. instruction execution cycles: the execution cycles shown in the table are minimums. the actual number of cycles may be increased when (1) contention occurs between instruction fetches and data access, or (2) when the destination register of the load instruction (memory register) and the register used by the next instruction are the same.
section 5 instruction set rev. 3.00 jul 08, 2005 page 54 of 484 rej09b0051-0300 5.1.1 data transfer instructions table 5.3 data transfer instructions compatibility instruction code operation cycles t bit sh2e sh4 new SH-2A/ sh2a- fpu mov #imm, rn 1110nnnniiiiiiii imm sign extension rn 1 D yes yes mov.w @(disp, pc), rn 1001nnnndddddddd (disp2+pc) sign extension rn 1 D yes yes mov.l @(disp, pc), rn 1101nnnndddddddd (disp4+pc) rn 1 D yes yes mov rm, rn 0110nnnnmmmm0011 rm rn 1 D yes yes mov.b rm, @rn 0010nnnnmmmm0000 rm (rn) 1 D yes yes mov.w rm, @rn 0010nnnnmmmm0001 rm (rn) 1 D yes yes mov.l rm, @rn 0010nnnnmmmm0010 rm (rn) 1 D yes yes mov.b @rm, rn 0110nnnnmmmm0000 (rm) sign extension rn 1 D yes yes mov.w @rm, rn 0110nnnnmmmm0001 (rm) sign extension rn 1 D yes yes mov.l @rm, rn 0110nnnnmmmm0010 (rm) rn 1 D yes yes mov.b rm, @-rn 0010nnnnmmmm0100 rn - 1 rn, rm (rn) 1 D yes yes mov.w rm, @-rn 0010nnnnmmmm0101 rn - 2 rn, rm (rn) 1 D yes yes mov.l rm, @-rn 0010nnnnmmmm0110 rn - 4 rn, rm (rn) 1 D yes yes mov.b @rm+, rn 0110nnnnmmmm0100 (rm) sign extension rn, rm + 1 rm 1 D yes yes mov.w @rm+, rn 0110nnnnmmmm0101 (rm) sign extension rn, rm + 2 rm 1 D yes yes mov.l @rm+, rn 0110nnnnmmmm0110 (rm) rn, rm + 4 rm 1 D yes yes mov.b r0, @(disp, rn) 10000000nnnndddd r0 (disp+rn) 1 D yes yes mov.w r0, @(disp, rn) 10000001nnnndddd r0 (disp2+rn) 1 D yes yes mov.l rm, @(disp, rn) 0001nnnnmmmmdddd rm (disp4+rn) 1 D yes yes mov.b @(disp, rm), r0 10000100mmmmdddd (disp+rm) sign extension r0 1 D yes yes mov.w @(disp, rm), r0 10000101mmmmdddd (disp2+rm) sign extension r0 1 D yes yes mov.l @(disp, rm), rn 0101nnnnmmmmdddd (disp4+rm) rn 1 D yes yes mov.b rm, @(r0, rn) 0000nnnnmmmm0100 rm (r0+rn) 1 D yes yes mov.w rm, @(r0, rn) 0000nnnnmmmm0101 rm (r0+rn) 1 D yes yes mov.l rm, @(r0, rn) 0000nnnnmmmm0110 rm (r0+rn) 1 D yes yes mov.b @(r0, rm), rn 0000nnnnmmmm1100 (r0+rm) sign extension rn 1 D yes yes mov.w @(r0, rm), rn 0000nnnnmmmm1101 (r0+rm) sign extension rn 1 D yes yes
section 5 instruction set rev. 3.00 jul 08, 2005 page 55 of 484 rej09b0051-0300 compatibility instruction code operation cycles t bit sh2e sh4 new SH-2A/ sh2a- fpu mov.l @(r0, rm), rn 0000nnnnmmmm1110 (r0+rm) rn 1 D yes yes mov.b r0, @(disp, gbr) 11000000dddddddd r0 (disp+gbr) 1 D yes yes mov.w r0, @(disp, gbr) 11000001dddddddd r0 (disp2+gbr) 1 D yes yes mov.l r0, @(disp, gbr) 11000010dddddddd r0 (disp4+gbr) 1 D yes yes mov.b @(disp, gbr), r0 11000100dddddddd (disp+gbr) sign extension r0 1 D yes yes mov.w @(disp, gbr), r0 11000101dddddddd (disp2+gbr) sign extension r0 1 D yes yes mov.l @(disp, gbr), r0 11000110dddddddd (disp4+gbr) r0 1 D yes yes mov.b r0, @rn+ 0100nnnn10001011 r0 (rn), rn + 1 rn 1 D yes mov.w r0, @rn+ 0100nnnn10011011 r0 (rn), rn + 2 rn 1 D yes mov.l r0, @rn+ 0100nnnn10101011 r0 (rn), rn + 4 rn 1 D yes mov.b @-rm, r0 0100mmmm11001011 rm - 1 rm, (rm) sign extension r0 1 D yes mov.w @-rm, r0 0100mmmm11011011 rm - 2 rm, (rm) sign extension r0 1 D yes mov.l @-rm, r0 0100mmmm11101011 rm - 4 rm, (rm) r0 1 D yes mov.b rm, @(disp12, rn) 0011nnnnmmmm0001 0000dddddddddddd rm (disp+rn) 1 D yes mov.w rm, @(disp12, rn) 0011nnnnmmmm0001 0001dddddddddddd rm (disp2+rn) 1 D yes mov.l rm, @(disp12, rn) 0011nnnnmmmm0001 0010dddddddddddd rm (disp4+rn) 1 D yes mov.b @(disp12, rm), rn 0011nnnnmmmm0001 0100dddddddddddd (disp+rm) sign extension rn 1 D yes mov.w @(disp12, rm), rn 0011nnnnmmmm0001 0101dddddddddddd (disp2+rm) sign extension rn 1 D yes mov.l @(disp12, rm), rn 0011nnnnmmmm0001 0110dddddddddddd (disp4+rm) rn 1 D yes mova @(disp, pc), r0 11000111dddddddd disp 4 + pc r0 1 D yes yes movi20 #imm20, rn 0000nnnniiii0000 iiiiiiiiiiiiiiii imm sign extension rn 1 D yes movi20s #imm20, rn 0000nnnniiii0001 iiiiiiiiiiiiiiii imm<<8 sign extension rn 1 D yes
section 5 instruction set rev. 3.00 jul 08, 2005 page 56 of 484 rej09b0051-0300 compatibility instruction code operation cycles t bit sh2e sh4 new SH-2A/ sh2a- fpu movml.l rm, @-r15 0100mmmm11110001 r15 - 4 r15, rm (r15) r15 - 4 r15, rm - 1 (r15) : r15 - 4 r15, r0 (r15) note: when rm = r15, read rm as pr 1 to 16 D yes movml.l @r15+, rn 0100nnnn11110101 (r15) r0, r15 + 4 r15 (r15) r1, r15 + 4 r15 : (r15) rn note: when rn = r15, read rn as pr 1 to 16 D yes movmu.l rm, @-r15 0100mmmm11110000 r15 - 4 r15, pr (r15) r15 - 4 r15, r14 (r15) : r15 - 4 r15, rm (r15) note: when rm = r15, read rm as pr 1 to 16 D yes movmu.l @r15+, rn 0100nnnn11110100 (r15) rn, r15 + 4 r15 (r15) rn + 1, r15 + 4 r15 : (r15) r14, r15 + 4 r15 (r15) pr note: when rn = r15, read rn as pr 1 to 16 D yes movrt rn 0000nnnn00111001 ~ t rn 1 D yes movt rn 0000nnnn00101001 t rn 1 D yes yes movu.b @(disp12,rm), rn 0011nnnnmmmm0001 1000dddddddddddd (disp+rm) zero extension rn 1 D yes movu.w @(disp12,rm),rn 0011nnnnmmmm0001 1001dddddddddddd (disp2+rm) zero extension rn 1 D yes nott 0000000001101000 ~ t t 1 opera- tion result yes pref @rn 0000nnnn10000011 (rn) operand cache 1 D yes
section 5 instruction set rev. 3.00 jul 08, 2005 page 57 of 484 rej09b0051-0300 compatibility instruction code operation cycles t bit sh2e sh4 new SH-2A/ sh2a- fpu swap.b rm, rn 0110nnnnmmmm1000 rm swap lower 2 bytes rn 1 D yes yes swap.w rm, rn 0110nnnnmmmm1001 rm swap upper/lower words rn 1 D yes yes xtrct rm, rn 0010nnnnmmmm1101 rm:rn middle 32 bits rn 1 D yes yes
section 5 instruction set rev. 3.00 jul 08, 2005 page 58 of 484 rej09b0051-0300 5.1.2 arithmetic operation instructions table 5.4 arithmetic operation instructions compatibility instruction code operation cycles t bit sh2e sh4 new SH-2A/ sh2a- fpu add rm, rn 0011nnnnmmmm1100 rn + rm rn 1 D yes yes add #imm, rn 0111nnnniiiiiiii rn + imm rn 1 D yes yes addc rm, rn 0011nnnnmmmm1110 rn + rm + t rn, carry t 1 carry yes yes addv rm, rn 0011nnnnmmmm1111 rn + rm rn, overflow t 1 overflow yes yes cmp/eq #imm, r0 10001000iiiiiiii when r0 = imm, 1 t otherwise, 0 t 1 com- parison result yes yes cmp/eq rm, rn 0011nnnnmmmm0000 when rn = rm, 1 t otherwise, 0 t 1com- parison result yes yes cmp/hs rm, rn 0011nnnnmmmm0010 when rn rm (unsigned), 1 t otherwise, 0 t 1com- parison result yes yes cmp/ge rm, rn 0011nnnnmmmm0011 when rn rm (signed), 1 t otherwise, 0 t 1com- parison result yes yes cmp/hi rm, rn 0011nnnnmmmm0110 when rn > rm (unsigned), 1 t otherwise, 0 t 1com- parison result yes yes cmp/gt rm, rn 0011nnnnmmmm0111 when rn > rm (signed), 1 t otherwise, 0 t 1 com- parison result yes yes cmp/pl rn 0100nnnn00010101 when rn > 0, 1 t otherwise, 0 t 1 com- parison result yes yes cmp/pz rn 0100nnnn00010001 when rn 0, 1 t otherwise, 0 t 1com- parison result yes yes cmp/str rm, rn 0010nnnnmmmm1100 when any bytes are equal, 1 t otherwise, 0 t 1com- parison result yes yes clips.b rn 0100nnnn10010001 when rn > (h'0000007f), (h'0000007f) rn, 1 cs when rn < (h'ffffff80), (h'ffffff80) rn, 1 cs 1 D yes
section 5 instruction set rev. 3.00 jul 08, 2005 page 59 of 484 rej09b0051-0300 compatibility instruction code operation cycles t bit sh2e sh4 new SH-2A/ sh2a- fpu clips.w rn 0100nnnn10010101 when rn > (h'00007fff), (h'00007fff) rn, 1 cs when rn < (h'ffff8000), (h'ffff8000) rn, 1 cs 1 D yes clipu.b rn 0100nnnn10000001 when rn > (h'000000ff), (h'000000ff) rn, 1 cs 1 D yes clipu.w rn 0100nnnn10000101 when rn > (h'0000ffff), (h'0000ffff) rn, 1 cs 1 D yes div1 rm, rn 0011nnnnmmmm0100 1-step division (rn rm) 1 calculati- on result yes yes div0s rm, rn 0010nnnnmmmm0111 msb of rn q, msb of rm m, m ^ q t 1calculati- on result yes yes div0u 0000000000011001 0 m/q/t 1 0 yes yes divs r0, rn 0100nnnn10010100 signed, rn r0 rn 32 32 32 bits 36 D yes divu r0, rn 0100nnnn10000100 unsigned, rn r0 rn 32 32 32 bits 34 D yes dmuls.l rm, rn 0011nnnnmmmm1101 signed, rn rm mach, macl 32 32 64 bits 2 D yes yes dmulu.l rm, rn 0011nnnnmmmm0101 unsigned, rn rm mach, macl 32 32 64 bits 2 D yes yes dt rn 0100nnnn00010000 rn - 1 rn; when rn = 0, 1 t when rn 0, 0 t 1com- parison result yes yes exts.b rm, rn 0110nnnnmmmm1110 rm sign-extended from byte rn 1 D yes yes exts.w rm, rn 0110nnnnmmmm1111 rm sign-extended from word rn 1 D yes yes extu.b rm, rn 0110nnnnmmmm1100 rm zero-extended from byte rn 1 D yes yes extu.w rm, rn 0110nnnnmmmm1101 rm zero-extended from word rn 1 D yes yes mac.l @rm+, @rn+ 0000nnnnmmmm1111 signed, (rn) (rm) + mac mac 32 32 + 64 64 bits 4 D yes yes mac.w @rm+, @rn+ 0100nnnnmmmm1111 signed, (rn) (rm) + mac mac 16 16 + 64 64 bits 3 D yes yes mul.l rm, rn 0000nnnnmmmm0111 rn rm macl 32 32 32 bits 2 D yes yes
section 5 instruction set rev. 3.00 jul 08, 2005 page 60 of 484 rej09b0051-0300 compatibility instruction code operation cycles t bit sh2e sh4 new SH-2A/ sh2a- fpu mulr r0, rn 0100nnnn10000000 r0 rn rn 32 32 32 bits 2yes muls.w rm, rn 0010nnnnmmmm1111 signed, rn rm macl 16 16 32 bits 1 D yes yes mulu.w rm, rn 0010nnnnmmmm1110 unsigned, rn rm macl 16 16 32 bits 1 D yes yes neg rm, rn 0110nnnnmmmm1011 0 - rm rn 1 D yes yes negc rm, rn 0110nnnnmmmm1010 0 - rm - t rn, borrow t 1 borrow yes yes sub rm, rn 0011nnnnmmmm1000 rn - rm rn 1 D yes yes subc rm, rn 0011nnnnmmmm1010 rn - rm - t rn, borrow t 1 borrow yes yes subv rm, rn 0011nnnnmmmm1011 rn - rm rn, underflow t 1 overflow yes yes
section 5 instruction set rev. 3.00 jul 08, 2005 page 61 of 484 rej09b0051-0300 5.1.3 logic operation instructions table 5.5 logic operation instructions compatibility instruction code operation cycles t bit sh2e sh4 new SH-2A/ sh2a- fpu and rm, rn 0010nnnnmmmm1001 rn & rm rn 1 D yes yes and #imm, r0 11001001iiiiiiii r0 & imm r0 1 D yes yes and.b #imm, @(r0, gbr) 11001101iiiiiiii (r0+gbr) & imm (r0+gbr) 3 D yes yes not rm, rn 0110nnnnmmmm0111 ~ rm rn 1 D yes yes or rm, rn 0010nnnnmmmm1011 rn | rm rn 1 D yes yes or #imm, r0 11001011iiiiiiii r0 | imm r0 1 D yes yes or.b #imm, @(r0, gbr) 11001111iiiiiiii (r0+gbr) | imm (r0+gbr) 3 D yes yes tas.b @rn 0100nnnn00011011 when (rn) = 0, 1 t, otherwise 0 t, 1 msb of (rn) 3test result yes yes tst rm, rn 0010nnnnmmmm1000 rn & rm; when result = 0, 1 t, otherwise 0 t 1test result yes yes tst #imm, r0 11001000iiiiiiii r0 & imm; when result = 0, 1 t, otherwise 0 t 1 test result yes yes tst.b #imm, @(r0, gbr) 11001100iiiiiiii (r0 + gbr) & imm; when result = 0, 1 t, otherwise 0 t 3 test result yes yes xor rm, rn 0010nnnnmmmm1010 rn ^ rm rn 1 D yes yes xor #imm, r0 11001010iiiiiiii r0 ^ imm r0 1 D yes yes xor.b #imm, @(r0, gbr) 11001110iiiiiiii (r0+gbr) ^ imm (r0+gbr) 3 D yes yes
section 5 instruction set rev. 3.00 jul 08, 2005 page 62 of 484 rej09b0051-0300 5.1.4 shift instructions table 5.6 shift instructions compatibility instruction code operation cycles t bit sh2e sh4 new SH-2A/ sh2a- fpu rotl rn 0100nnnn00000100 t rn msb 1 msb yes yes rotr rn 0100nnnn00000101 lsb rn t 1 lsb yes yes rotcl rn 0100nnnn00100100 t rn t1msbyesyes rotcr rn 0100nnnn00100101 t rn t 1 lsb yes yes shad rm, rn 0100nnnnmmmm1100 when rm 0, rn<>|rm| [msb rn] 1 D yes shal rn 0100nnnn00100000 t rn 01msbyesyes shar rn 0100nnnn00100001 msb rn t 1 lsb yes yes shld rm, rn 0100nnnnmmmm1101 when rm 0, rn<>|rm| [0 rn] 1 D yes shll rn 0100nnnn00000000 t rn 01msbyesyes shlr rn 0100nnnn00000001 0 rn t 1 lsb yes yes shll2 rn 0100nnnn00001000 rn<<2 rn 1 D yes yes shlr2 rn 0100nnnn00001001 rn>>2 rn 1 D yes yes shll8 rn 0100nnnn00011000 rn<<8 rn 1 D yes yes shlr8 rn 0100nnnn00011001 rn>>8 rn 1 D yes yes shll16 rn 0100nnnn00101000 rn<<16 rn 1 D yes yes shlr16 rn 0100nnnn00101001 rn>>16 rn 1 D yes yes
section 5 instruction set rev. 3.00 jul 08, 2005 page 63 of 484 rej09b0051-0300 5.1.5 branch instructions table 5.7 branch instructions compatibility instruction code operation cycles t bit sh2e sh4 new SH-2A/ sh2a- fpu bf label 10001011dddddddd when t = 0, disp 2 + pc pc, when t = 1, nop 3/1 * D yes yes bf/s label 10001111dddddddd delayed branch, when t = 0, disp 2 + pc pc, when t = 1, nop 2/1 * D yes yes bt label 10001001dddddddd when t = 1, disp 2 + pc pc, when t = 0, nop 3/1 * D yes yes bt/s label 10001101dddddddd delayed branch, when t = 1, disp 2 + pc pc, when t = 0, nop 2/1 * D yes yes bra label 1010dddddddddddd delayed branch, disp 2 + pc pc 2 D yes yes braf rm 0000mmmm00100011 delayed branch, rm + pc pc 2 D yes yes bsr label 1011dddddddddddd delayed branch, pc pr, disp 2 + pc pc 2 D yes yes bsrf rm 0000mmmm00000011 delayed branch, pc pr, rm + pc pc 2 D yes yes jmp @rm 0100mmmm00101011 delayed branch, rm pc 2 D yes yes jsr @rm 0100mmmm00001011 delayed branch, pc pr, rm pc 2 D yes yes jsr/n @rm 0100mmmm01001011 pc - 2 pr, rm pc 3 D yes jsr/n @@(disp8, tbr) 10000011dddddddd pc - 2 pr, (disp4+tbr) pc 5 D yes rts 0000000000001011 delayed branch, pr pc 2 D yes yes rts/n 0000000001101011 pr pc 3 D yes rtv/n rm 0000mmmm01111011 rm r0, pr pc 3 D yes note: * one state when the program does not branh.
section 5 instruction set rev. 3.00 jul 08, 2005 page 64 of 484 rej09b0051-0300 5.1.6 system control instructions table 5.8 system control instructions compatibility instruction code operation cycles t bit sh2e sh4 new SH-2A/ sh2a- fpu clrt 0000000000001000 0 t10yesyes clrmac 0000000000101000 0 mach, macl 1 D yes yes ldbank @rm, r0 0100mmmm11100101 (specified register bank entry) r0 6 D yes ldc rm, sr 0100mmmm00001110 rm sr 3 lsb yes yes ldc rm, tbr 0100mmmm01001010 rm tbr 1 D yes ldc rm, gbr 0100mmmm00011110 rm gbr 1 D yes yes ldc rm, vbr 0100mmmm00101110 rm vbr 1 D yes yes ldc.l @rm+, sr 0100mmmm00000111 (rm) sr, rm + 4 rm 5 lsb yes yes ldc.l @rm+, gbr 0100mmmm00010111 (rm) gbr, rm + 4 rm 1 D yes yes ldc.l @rm+, vbr 0100mmmm00100111 (rm) vbr, rm + 4 rm 1 D yes yes lds rm, mach 0100mmmm00001010 rm mach 1 D yes yes lds rm, macl 0100mmmm00011010 rm macl 1 D yes yes lds rm, pr 0100mmmm00101010 rm pr 1 D yes yes lds.l @rm+, mach 0100mmmm00000110 (rm) mach, rm + 4 rm 1 D yes yes lds.l @rm+, macl 0100mmmm00010110 (rm) macl, rm + 4 rm 1 D yes yes lds.l @rm+, pr 0100mmmm00100110 (rm) pr, rm + 4 rm 1 D yes yes nop 0000000000001001 no operation 1 D yes yes resbank 0000000001011011 bank r0 to r14, gbr, mach, macl, pr 9 * D yes rte 0000000000101011 delayed branch, stack area pc/sr 6 D yes yes sett 0000000000011000 1 t11yesyes sleep 0000000000011011 sleep 5 D yes yes stbank r0, @rn 0100nnnn11100001 r0 (specified register bank entry) 7 D yes stc sr, rn 0000nnnn00000010 sr rn 2 D yes yes stc tbr, rn 0000nnnn01001010 tbr rn 1 D yes stc gbr, rn 0000nnnn00010010 gbr rn 1 D yes yes stc vbr, rn 0000nnnn00100010 vbr rn 1 D yes yes stc.l sr, @- rn 0100nnnn00000011 rn - 4 rn, sr (rn) 2 D yes yes stc.l gbr, @- rn 0100nnnn00010011 rn - 4 rn, gbr (rn) 1 D yes yes stc.l vbr, @- rn 0100nnnn00100011 rn - 4 rn, vbr (rn) 1 D yes yes
section 5 instruction set rev. 3.00 jul 08, 2005 page 65 of 484 rej09b0051-0300 compatibility instruction code operation cycles t bit sh2e sh4 new SH-2A/ sh2a- fpu sts mach, rn 0000nnnn00001010 mach rn 1 D yes yes sts macl, rn 0000nnnn00011010 macl rn 1 D yes yes sts pr, rn 0000nnnn00101010 pr rn 1 D yes yes sts.l mach, @-rn 0100nnnn00000010 rn - 4 rn, mach (rn) 1 D yes yes sts.l macl, @-rn 0100nnnn00010010 rn - 4 rn, macl (rn) 1 D yes yes sts.l pr, @-rn 0100nnnn00100010 rn - 4 rn, pr (rn) 1 D yes yes trapa #imm 11000011iiiiiiii pc/sr stack area, (imm 4 + vbr) pc 5 D yes yes notes: the execution cycles shown in the table are minimums. the actual number of cycles may be increased when (1) contention occurs between instruction fetches and data access, or (2) when the destination register of the load instruction (memory register) and the register used by the next instruction are the same. * in the event of bank overflow, the number of states is 19.
section 5 instruction set rev. 3.00 jul 08, 2005 page 66 of 484 rej09b0051-0300 5.1.7 floating-point instructions table 5.9 floating-point instructions compatibility instruction code operation cycles t bit sh2e sh4 new SH-2A/ sh2a- fpu fabs frn 1111nnnn01011101 |frn| frn 1 D yes yes fabs drn 1111nnn001011101 |drn| drn 1 D yes fadd frm, frn 1111nnnnmmmm0000 frn + frm frn 1 D yes yes fadd drm, drn 1111nnn0mmm00000 drn + drm drn 6 D yes fcmp/eq frm, frn 1111nnnnmmmm0100 (frn=frm)? 1:0 t1 com- parison result yes yes fcmp/eq drm, drn 1111nnn0mmm00100 (drn=drm)? 1:0 t2com- parison result yes fcmp/gt frm, frn 1111nnnnmmmm0101 (frn>frm)? 1:0 t1com- parison result yes yes fcmp/gt drm, drn 1111nnn0mmm00101 (drn>drm)? 1:0 t2com- parison result yes fcnvds drm, fpul 1111mmm010111101 (float) drm fpul 2 D yes fcnvsd fpul, drn 1111nnn010101101 (double) fpul drn 2 D yes fdiv frm, frn 1111nnnnmmmm0011 frn/frm frn 10 D yes yes fdiv drm, drn 1111nnn0mmm00011 drn/drm drn 23 D yes fldi0 frn 1111nnnn10001101 0 00000000 frn 1 D yes yes fldi1 frn 1111nnnn10011101 0 3f800000 frn 1 D yes yes flds frm, fpul 1111mmmm00011101 frm fpul 1 D yes yes float fpul,frn 1111nnnn00101101 (float) fpul frn 1 D yes yes float fpul,drn 1111nnn000101101 (double) fpul drn 2 D yes fmac fr0,frm,frn 1111nnnnmmmm1110 fr0 frm + frn frn 1 D yes yes fmov frm, frn 1111nnnnmmmm1100 frm frn 1 D yes yes fmov drm, drn 1111nnn0mmm01100 drm drn 2 D yes fmov.s @(r0, rm), frn 1111nnnnmmmm0110 (r0+rm) frn 1 D yes yes fmov.d @(r0, rm), drn 1111nnn0mmmm0110 (r0+rm) drn 2 D yes fmov.s @rm+, frn 1111nnnnmmmm1001 (rm) frn, rm+ = 4 1 D yes yes fmov.d @rm+, drn 1111nnn0mmmm1001 (rm) drn, rm+ = 8 2 D yes fmov.s @rm, frn 1111nnnnmmmm1000 (rm) frn 1 D yes yes fmov.d @rm, drn 1111nnn0mmmm1000 (rm) drn 2 D yes
section 5 instruction set rev. 3.00 jul 08, 2005 page 67 of 484 rej09b0051-0300 compatibility instruction code operation cycles t bit sh2e sh4 new SH-2A/ sh2a- fpu fmov.s @(disp12,rm),frn 0011nnnnmmmm0001 0111dddddddddddd (disp4+rm) frn 1 D yes fmov.d @(disp12,rm),drn 0011nnn0mmmm0001 0111dddddddddddd (disp8+rm) drn 2 D yes fmov.s frm, @( r0,rn ) 1111nnnnmmmm0111 frm (r0+rn) 1 D yes yes fmov.d drm, @( r0,rn ) 1111nnnnmmm00111 drm (r0+rn) 2 D yes fmov.s frm, @-rn 1111nnnnmmmm1011 rn- = 4, frm (rn) 1 D yes yes fmov.d drm, @-rn 1111nnnnmmm01011 rn- = 8, drm (rn) 2 D yes fmov.s frm, @rn 1111nnnnmmmm1010 frm (rn) 1 D yes yes fmov.d drm, @rn 1111nnnnmmm01010 drm (rn) 2 D yes fmov.s frm, @(disp12,rn) 0011nnnnmmmm00010 011dddddddddddd frm (disp4+rn) 1 D yes fmov.d drm, @(disp12,rn) 0011nnnnmmm000010 011dddddddddddd drm (disp8+rn) 2 D yes fmul frm, frn 1111nnnnmmmm0010 frn frm frn 1 D yes yes fmul drm, drn 1111nnn0mmm00010 drn drm drn 6 D yes fneg frn 1111nnnn01001101 -frn frn 1 D yes yes fneg drn 1111nnn001001101 -drn drn 1 D yes fschg 1111001111111101 fpscr.sz = ~ fpscr.sz 1 D yes fsqrt frn 1111nnnn01101101 frn frn 9 D yes fsqrt drn 1111nnn001101101 drn drn 22 D yes fsts fpul,frn 1111nnnn00001101 fpul frn 1 D yes yes fsub frm, frn 1111nnnnmmmm0001 frn - frm frn 1 D yes yes fsub drm, drn 1111nnn0mmm00001 drn - drm drn 6 D yes ftrc frm, fpul 1111mmmm00111101 (long) frm fpul 1 D yes yes ftrc drm, fpul 1111mmm000111101 (long) drm fpul 2 D yes
section 5 instruction set rev. 3.00 jul 08, 2005 page 68 of 484 rej09b0051-0300 5.1.8 fpu-related cpu instructions table 5.10 fpu-related cpu instructions compatibility instruction code operation cycles t bit sh2e sh4 new SH-2A/ sh2a- fpu lds rm,fpscr 0100mmmm01101010 rm fpscr 1 D yes yes lds rm,fpul 0100mmmm01011010 rm fpul 1 D yes yes lds.l @rm+, fpscr 0100mmmm01100110 (rm) fpscr, rm+ = 4 1 D yes yes lds.l @rm+, fpul 0100mmmm01010110 (rm) fpul, rm+ = 4 1 D yes yes sts fpscr, rn 0000nnnn01101010 fpscr rn 1 D yes yes sts fpul,rn 0000nnnn01011010 fpul rn 1 D yes yes sts.l fpscr,@-rn 0100nnnn01100010 rn- = 4, fpcsr (rn) 1 D yes yes sts.l fpul,@-rn 0100nnnn01010010 rn- = 4, fpul (rn) 1 D yes yes
section 5 instruction set rev. 3.00 jul 08, 2005 page 69 of 484 rej09b0051-0300 5.1.9 bit manipulation instructions table 5.11 bit manipulation instructions compatibility instruction code operation cycles t bit sh2e sh4 new SH-2A/ sh2a- fpu band.b #imm3,@(disp12,rn) 0011nnnn0iii1001 0100dddddddddddd (imm of (disp+rn)) & t t 3 opera- tion result yes bandnot.b #imm3,@(disp12,rn) 0011nnnn0iii1001 1100dddddddddddd ~ (imm of (disp+rn)) & t t 3 opera- tion result yes bclr.b #imm3,@(disp12,rn) 0011nnnn0iii1001 0000dddddddddddd 0 (imm of (disp+rn)) 3 D yes bclr #imm3, rn 10000110nnnn0iii 0 imm of rn 1 D yes bld.b #imm3,@(disp12,rn) 0011nnnn0iii1001 0011dddddddddddd (imm of (disp+rn)) t 3 opera- tion result yes bld #imm3, rn 10000111nnnn1iii imm of rn t 1 opera- tion result yes bldnot.b #imm3,@(disp12,rn) 0011nnnn0iii1001 1011dddddddddddd ~ (imm of (disp+rn)) t 3 opera- tion result yes bor.b #imm3,@(disp12,rn) 0011nnnn0iii1001 0101dddddddddddd (imm of (disp+ rn)) | t t 3 opera- tion result yes bornot.b #imm3,@(disp12,rn) 0011nnnn0iii1001 1101dddddddddddd ~ (imm of (disp+ rn)) | t t 3 opera- tion result yes bset.b #imm3,@(disp12,rn) 0011nnnn0iii1001 0001dddddddddddd 1 (imm of (disp+rn)) 3 D yes bset #imm3, rn 10000110nnnn1iii 1 imm of rn 1 D yes bst.b #imm3,@(disp12,rn) 0011nnnn0iii1001 0010dddddddddddd t (imm of (disp+rn)) 3 D yes bst #imm3, rn 10000111nnnn0iii t imm of rn 1 D yes bxor.b #imm3, @(disp12, rn) 0011nnnn0iii1001 0110dddddddddddd (imm of (disp+ rn)) ^ t t 3 opera- tion result yes
section 5 instruction set rev. 3.00 jul 08, 2005 page 70 of 484 rej09b0051-0300
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 71 of 484 rej09b0051-0300 section 6 instruction descriptions 6.1 overview of new instructions in the SH-2A/sh2a-fpu, new instructions have been added in vacant locations other than instruction codes assigned to sh-2e cpu instructions (instruction codes with upper 4 bits of 0000 to 1110) and sh4 fpu instructions (instruction codes with upper 4 bits of 1111). however, the SH-2A does not support the following sh4 fpu instructions: (a) fmov instructions specifying xdm/xdn, (b) the frchg instruction, and (c) fipr, and ftrv instructions. this section gives detailed descriptions of the new instructions. SH-2A 0000 . . . to 1110 . . . 1111 . . . cpu instructions (sh2e + new instructions) fpu instructions (sh4, excluding (a), (b), and (c)) the new instructions are those described in (1) to (14) below. (1) to (3) are 32-bit fixed-length instructions, and (4) to (14) are 16-bit fixed-length instructions. (1) immediate transfer instructions movi20, movi20s these instructions transfer 20-bit immediate data in the instruction code to a register. combination with one of these instructions simplifies generation of a 28-bit address, making it possible to specify on-chip memory addresses for a maximum of 256 mb.
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 72 of 484 rej09b0051-0300 (2) structure access instructions mov.b/w/l rm, @(disp12, rn), mov.b/w/l @(disp12, rm), rn movu.b/w @(disp12, rm), rn fmov.s frm, @(disp12, rn), fmov.s @(disp12, rm), frn fmov.d drm, @(disp12, rn), fmov.d @(disp12, rm), drn these instructions reference memory by specifying a 12-bit displacement located in the instruction code. an movu unsigned load instruction that automatically performs execution of zero extension has also been added. (3) bit manipulation instructions (operating on memory) band.b #imm3, @(disp12, rn), bor.b #imm3, @(disp12, rn) bclr.b #imm3, @(disp12, rn), bset.b #imm3, @(disp12, rn) bst.b #imm3, @(disp12, rn), bld.b #imm3, @(disp12, rn) bxor.b #imm3, @(disp12, rn) bandnot.b #imm3, @(disp12, rn), bornot.b #imm3, @(disp12, rn) bldnot.b #imm3, @(disp12, rn) the band.b, bor.b, and bxor.b instructions perform logical operations between a bit in memory and the t bit, and store the result in the t bit. the bclr.b and bset.b instructions manipulate a bit in memory. the bst.b and bld.b instructions execute a transfer between a bit in memory and the t bit. the bandnot.b and bornot.b instructions perform logical operations between the value resulting from inverting a bit in memory and the t bit, and store the result in the t bit. the bldnot.b instruction inverts a bit in memory and stores the result in the t bit. bits other than the specified bit are not affected. (4) bit manipulation instructions (operating on a general register) bclr #imm3, rn, bset #imm3, rn bst #imm3, rn , bld #imm3, rn the bclr and bset instructions manipulate one of the lsb 8 bits of a general register rn. the bst and bld instructions execute a transfer between one of the lsb 8 bits of a general register rn and the t bit. bits other than the specified bit are not affected.
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 73 of 484 rej09b0051-0300 (5) multiplication result rn storage instruction mulr mulr performs a 32-bit x 32-bit multiplication, and stores the lower 32 bits of the result in a general register rn. (6) batch division instructions divs, divu these instructions perform batch 32-bit 32-bit division. the divu instruction performs division of unsigned data, and the divs instruction performs division of signed data. (7) saturation value comparison instructions clips, clipu these instructions perform a comparison with a saturation value, and store the saturation upper- limit value in a general register rn if the general register rn contents exceed the saturation upper- limit value, or store the saturation lower-limit value in general register rn if the general register rn contents are less than the saturation upper-limit value. only byte and word saturation values are supported. (8) barrel shift instructions shad, shld these instructions shift arbitrary bits. two kinds of instructions are provided, for an arithmetic shift and a logical shift. (9) multiple register save/restore instructions movml, movmu these instructions save a number of consecutive registers to memory, or restore a number of consecutive registers from memory. it is possible to specify a general register rn, and to save or restore consecutive general registers higher than or lower than the specified rn.
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 74 of 484 rej09b0051-0300 (10) t bit inversion and transfer instructions movrt, nott these instructions invert the t bit and transfer the resulting value to a general register rn or the t bit. (11) register bank related instructions resbank, stbank, ldbank these are register bank related instructions that are provided in order to speed up interrupt handling. (12) reverse stack transfer instructions mov.b/w/l these are transfer instructions in which the stack expansion direction is reversed. (13) unconditional branch instructions with no delay slot jsr/n, rts/n instructions that do not have a delay slot are provided in order to reduce the code size by cutting down on the number of unnecessary nop instructions. (14) cache-related instruction pref an sh3-dsp cache-related instruction is provided.
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 75 of 484 rej09b0051-0300 6.2 format of instruction descriptions format of this section: the format used for describing instructions is as shown below. instruction name instruction function (explanation instruction type instruction function of instruction name) instruction set compatibility format abstract code cycles t bit shown in assembler input format. imm and disp are numeric values, expressions, or symbols. summarizes the operation. shown in msb ? lsb order. value in case of no-wait operation. shows the value of the t bit after execution of the instruction. description describes the operation of the instruction. notes mentions points requiring particular attention when using the instruction. operation shows the operation of the instruction in c. provided as a reference to explain the operation of the instruction. the use of the following resources is assumed here. unsigned char read_byte (unsigned long addr); unsigned short read_word (unsigned long addr); unsigned int read_int (unsigned long addr); unsigned long read_long (unsigned long addr); unsigned double read_quad (unsigned long addr); the size of address addr is returned. a word read from other than a 2n address or a longword read from other than a 4n address will be detected as an address error. unsigned long read_bank_long (unsigned long addr); the contents of the register bank entry indicated by the contents of address addr are returned.
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 76 of 484 rej09b0051-0300 unsigned char write_byte (unsigned long addr, unsigned long data); unsigned short write_word (unsigned long addr, unsigned long data); unsigned int write_int (unsigned long addr, unsigned long data); unsigned long write_long (unsigned long addr, unsigned long data); unsigned double write_quad (unsigned long addr, unsigned long data); data data is written to address addr using the respective size. a word write to other than a 2n address or a longword write to other than a 4n address will be detected as an address error. unsigned long write_bank_long (unsigned long add, unsigned long data); data data is written to the register bank entry indicated by the contents of address addr. unsigned long r[16]; unsigned long sr, gbr, vbr, tbr; unsigned long mach, macl, pr; unsigned long pc; respective registers struct bank { unsigned long rn_bank[15]; unsigned long gbr_bank; unsigned long mach_bank; unsigned long macl_bank; unsigned long pr_bank; unsigned long ivn; } ; bank register_bank[512]; register bank structure definition (vto: interrupt vector table address offset) struct sr0 { unsigned long dummy0:17; unsigned long bo0:1 unsigned long cs0:1; unsigned long dummy1:3; unsigned long m0:1; unsigned long q0:1; unsigned long i0:4;
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 77 of 484 rej09b0051-0300 unsigned long dummy2:2; unsigned long s0:1; unsigned long t0:1; } ; sr structure definition #define bo ((* (struct sr0 *) (&sr)).bo0) #define cs ((* (struct sr0 *) (&sr)).cs0) #define m ((* (struct sr0 *) (&sr)).m0) #define q ((* (struct sr0 *) (&sr)).q0) #define i ((* (struct sr0 *) (&sr)).i0) #define s ((* (struct sr0 *) (&sr)).s0) #define t ((* (struct sr0 *) (&sr)).t0) definition of bits in sr error (char *er); error indication function these are floating-point number definition statements. #define pzero 0 #define nzero 1 #define denorm 2 #define norm 3 #define pinf 4 #define ninf 5 #define qnan 6 #define snan 7 #define eq 0 #define gt 1 #define lt 2 #define uo 3 #define invalid 4 #define fadd 0 #define fsub 1 #define cause 0x0003f000 /* fpscr(bit17-12) */
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 78 of 484 rej09b0051-0300 #define set_e 0x00020000 /* fpscr(bit17) */ #define set_v 0x00010040 /* fpscr(bit16,6) */ #define set_z 0x00008020 /* fpscr(bit15,5) */ #define set_o 0x00004010 /* fpscr(bit14,4) */ #define set_u 0x00002008 /* fpscr(bit13,3) */ #define set_i 0x00001004 /* fpscr(bit12,2) */ #define enable_voui 0x00000b80 /* fpscr(bit11,9-7) */ #define enable_v 0x00000800 /* fpscr(bit11) */ #define enable_z 0x00000400 /* fpscr(bit10) */ #define enable_oui 0x00000380 /* fpscr(bit9-7) */ #define enable_i 0x00000080 /* fpscr(bit7) */ #define flag 0x0000007c /* fpscr(bit6-2) */ #define fpscr_fr fpscr>>21&1 #define fpscr_pr fpscr>>19&1 #define fpscr_dn fpscr>>18&1 #define fpscr_i fpscr>>12&1 #define fpscr_rm fpscr&1 #define fr_hex frf.l[ fpscr_fr] #define fr frf.f[ fpscr_fr] #define dr_hex frf.f[ fpscr_fr] #define dr frf.d[ fpscr_fr] union { int l[2][16]; float f[2][16]; double d[2][8]; } frf; int fpscr; int sign_of(int n) { return(fr_hex[n]>>31); } int data_type_of(int n) {
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 79 of 484 rej09b0051-0300 int abs; abs = fr_hex[n] & 0x7fffffff; if(fpscr_pr == 0) { /* single-precision */ if(abs < 0x00800000){ if((fpscr_dn == 1) || (abs == 0x00000000)){ if(sign_of(n) == 0) {zero(n, 0); return(pzero);} else {zero(n, 1); return(nzero);} } else return(denorm); } else if(abs < 0x7f800000) return(norm); else if(abs == 0x7f800000) { if(sign_of(n) == 0) return(pinf); else return(ninf); } else if(abs < 0x7fc00000) return(qnan); else return(snan); } else { /* double-precision */ if(abs < 0x00100000){ if((fpscr_dn == 1) || ((abs == 0x00000000) && (fr_hex[n+1] == 0x00000000)){ if(sign_of(n) == 0) {zero(n, 0); return(pzero);} else {zero(n, 1); return(nzero);} } else return(denorm); } else if(abs < 0x7ff00000) return(norm); else if((abs == 0x7ff00000) && (fr_hex[n+1] == 0x00000000)) { if(sign_of(n) == 0) return(pinf); else return(ninf); } else if(abs < 0x7ff80000) return(qnan); else return(snan);
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 80 of 484 rej09b0051-0300 } } void register_copy(int m,n) { fr[n] = fr[m]; if(fpscr_pr == 1) fr[n+1] = fr[m+1]; } void normal_faddsub(int m,n,type) { union { float f; int l; } dstf,srcf; union { long d; int l[2]; } dstd,srcd; union { /* ?long double? format: */ long double x; /* 1-bit sign */ int l[4]; /* 15-bit exponent */ } dstx; /* 112-bit mantissa */ if(fpscr_pr == 0) { if(type == fadd) srcf.f = fr[m]; else srcf.f = -fr[m]; dstd.d = fr[n]; /* conversion from single-precision to double-precision */ dstd.d += srcf.f; if(((dstd.d == fr[n]) && (srcf.f != 0.0)) || ((dstd.d == srcf.f) && (fr[n] != 0.0))) { set_i(); if(sign_of(m)^ sign_of(n)) { dstd.l[1] -= 1; if(dstd.l[1] == 0xffffffff) dstd.l[0] -= 1; } } if(dstd.l[1] & 0x1fffffff) set_i();
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 81 of 484 rej09b0051-0300 dstf.f += srcf.f; /* round to nearest */ if(fpscr_rm == 1) { dstd.l[1] &= 0xe0000000; /* round to zero */ dstf.f = dstd.d; } check_single_exception(&fr[n],dstf.f); } else { if(type == fadd) srcd.d = dr[m>>1]; else srcd.d = -dr[m>>1]; dstx.x = dr[n>>1]; /* conversion from double-precision to extended double-precision */ dstx.x += srcd.d; if(((dstx.x == dr[n>>1]) && (srcd.d != 0.0)) || ((dstx.x == srcd.d) && (dr[n>>1] != 0.0)) ) { set_i(); if(sign_of(m)^ sign_of(n)) { dstx.l[3] -= 1; if(dstx.l[3] == 0xffffffff) {dstx.l[2] -= 1; if(dstx.l[2] == 0xffffffff) {dstx.l[1] -= 1; if(dstx.l[1] == 0xffffffff) {dstx.l[0] -= 1;}}} } } if((dstx.l[2] & 0x0fffffff) || dstx.l[3]) set_i(); dst.d += srcd.d; /* round to nearest */ if(fpscr_rm == 1) { dstx.l[2] &= 0xf0000000; /* round to zero */ dstx.l[3] = 0x00000000; dst.d = dstx.x; } check_double_exception(&dr[n>>1] ,dst.d); } } void normal_fmul(int m,n) { union {
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 82 of 484 rej09b0051-0300 float f; int l; } tmpf; union { double d; int l[2]; } tmpd; union { long double x; int l[4]; } tmpx; if(fpscr_pr == 0) { tmpd.d = fr[n]; /* single-precision to double-precision */ tmpd.d *= fr[m]; /* precise creation */ tmpf.f *= fr[m]; /* round to nearest */ if(tmpf.f != tmpd.d) set_i(); if((tmpf.f > tmpd.d) && (fpscr_rm == 1)) { tmpf.l -= 1; /* round to zero */ } check_single_exception(&fr[n],tmpf.f); } else { tmpx.x = dr[n>>1]; /* single-precision to double-precision */ tmpx.x *= dr[m>>1]; /* precise creation */ tmpd.d *= dr[m>>1]; /* round to nearest */ if(tmpd.d != tmpx.x) set_i(); if(tmpd.d > tmpx.x) && (fpscr_rm == 1)) { tmpd.l[1] -= 1; /* round to zero */ if(tmpd.l[1] == 0xffffffff) tmpd.l[0] -= 1; } check_double_exception(&dr[n>>1], tmpd.d); } } void check_single_exception(float *dst,result) { union {
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 83 of 484 rej09b0051-0300 float f; int l; } tmp; float abs; if(result < 0.0) tmp.l = 0xff800000; /* ? infinity */ else tmp.l = 0x7f800000; /* + infinity */ if(result == tmp.f) { set_o(); set_i(); if(fpscr_rm == 1) { tmp.l -= 1; /* maximum value of normalized number */ result = tmp.f; } } if(result < 0.0) abs = -result; else abs = result; tmp.l = 0x00800000; /* minimum value of normalized number */ if(abs < tmp.f) { if((fpscr_dn == 1) && (abs != 0.0)) { set_i(); if(result < 0.0) result = -0.0; /* zeroize denormalized number */ else result = 0.0; } if(fpscr_i == 1) set_u(); } if(fpscr & enable_oui) fpu_exception_trap(); else *dst = result; } void check_double_exception(double *dst,result) { union { double d; int l[2]; } tmp; double abs; if(result < 0.0) tmp.l[0] = 0xfff00000; /* ? infinity */
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 84 of 484 rej09b0051-0300 else tmp.l[0] = 0x7ff00000; /* + infinity */ tmp.l[1] = 0x00000000; if(result == tmp.d) set_o(); set_i(); if(fpscr_rm == 1) { tmp.l[0] -= 1; tmp.l[1] = 0xffffffff; result = tmp.d; /* maximum value of normalized number */ } } if(result < 0.0) abs = -result; else abs = result; tmp.l[0] = 0x00100000; /* minimum value of normalized number */ tmp.l[1] = 0x00000000; if(abs < tmp.d) { if((fpscr_dn == 1) && (abs != 0.0)) { set_i(); if(result < 0.0) result = -0.0; /* zeroize denormalized number */ else result = 0.0; } if(fpscr_i == 1) set_u(); } if(fpscr & enable_oui) fpu_exception_trap(); else *dst = result; } int check_product_invalid(int m,n) { return(check_product_infinity(m,n) && ((data_type_of(m) == pzero) || (data_type_of(n) == pzero) || (data_type_of(m) == nzero) || (data_type_of(n) == nzero))); } int check_product_infinity(int m,n) { return((data_type_of(m) == pinf) || (data_type_of(n) == pinf) ||
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 85 of 484 rej09b0051-0300 (data_type_of(m) == ninf) || (data_type_of(n) == ninf)); } int check_positive_infinity(int m,n) { return(((check_product_infinity(m,n) && (~sign_of(m)^ sign_of(n))) || ((check_product_infinity(m+1,n+1) && (~sign_of(m+1)^ sign_of(n+1))) || ((check_product_infinity(m+2,n+2) && (~sign_of(m+2)^ sign_of(n+2))) || ((check_product_infinity(m+3,n+3) && (~sign_of(m+3)^ sign_of(n+3)))); } int check_negative_infinity(int m,n) { return(((check_product_infinity(m,n) && (sign_of(m)^ sign_of(n))) || ((check_product_infinity(m+1,n+1) && (sign_of(m+1)^ sign_of(n+1))) || ((check_product_infinity(m+2,n+2) && (sign_of(m+2)^ sign_of(n+2))) || ((check_ product_infinity(m+3,n+3) && (sign_of(m+3)^ sign_of(n+3)))); } void clear_cause () {fpscr &= ~cause;} void set_e() {fpscr |= set_e; fpu_exception_trap();} void set_v() {fpscr |= set_v;} void set_z() {fpscr |= set_z;} void set_o() {fpscr |= set_o;} void set_u() {fpscr |= set_u;} void set_i() {fpscr |= set_i;} void invalid(int n) { set_v(); if((fpscr & enable_v) == 0 qnan(n); else fpu_exception_trap(); } void dz(int n,sign)
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 86 of 484 rej09b0051-0300 { set_z(); if((fpscr & enable_z) == 0 inf(n,sign); else fpu_exception_trap(); } void zero(int n,sign) { if(sign == 0) fr_hex [n] = 0x00000000; else fr_hex [n] = 0x80000000; if (fpscr_pr==1) fr_hex [n+1] = 0x00000000; } void inf(int n,sign) { if (fpscr_pr==0) { if(sign == 0) fr_hex [n] = 0x7f800000; else fr_hex [n] = 0xff800000; } else { if(sign == 0) fr_hex [n] = 0x7ff00000; else fr_hex [n] = 0xfff00000; fr_hex [n+1] = 0x00000000; } } void qnan(int n) { if (fpscr_pr==0) fr[n] = 0x7fbfffff; else { fr[n] = 0x7ff7ffff; fr[n+1] = 0xffffffff; } }
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 87 of 484 rej09b0051-0300 example an example is shown using assembler mnemonics, indicating the states before and after execution of the instruction. italics (e.g., .align ) indicate an assembler control instruction. the meaning of the assembler control instructions is given below. for details, refer to the cross-assembler user?s manual. .org location counter setting .data.w word integer data allocation .data.l longword integer data allocation .sdata string data allocation .align 2 2-byte boundary alignment .align 4 4-byte boundary alignment .align 32 32-byte boundary alignment .arepeat 16 16-times repeat expansion .arepeat 32 32-times repeat expansion .aendr count-specification repeat expansion end note: sh series cross-assembler version 1.0 does not support conditional assembler functions.
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 88 of 484 rej09b0051-0300 6.3 new instructions 6.3.1 band bit and bit manipulation instruction bit logical and SH-2A/sh2a-fpu (new) format abstract code cycle t bit band.b #imm3, @(disp12,rn) ( of (disp+rn)) & t t 0011nnnn0iii10010100dddddddddddd 3 operation result description ands a specified bit in memory at the address indicated by (disp + rn) with the t bit, and stores the result in the t bit. the bit number is specified by 3-bit immediate data. with this instruction, data is read from memory as a byte unit. band.b #imm3, @(disp12, rn) 70 & t t (disp+rn) specified by #imm3
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 89 of 484 rej09b0051-0300 operation bandm (long d, long i, long n) /*band.b #imm3, @(disp12, rn) */ { long disp, imm, temp, assignbit; disp = (0x00000fff & (long)d); imm= (0x00000007&(long)i); temp= (long) read_byte (r[n]+disp); assignbit =(0x00000001< section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 90 of 484 rej09b0051-0300 6.3.2 bandnot bit andnot bit manipulation instruction bit not logical and SH-2A/sh2a-fpu (new) format abstract code cycle t bit bandnot.b #imm3, @(disp12,rn) ~ ( of (disp+rn)) & t t 0011nnnn0iii10011100dddddddddddd 3 operation result description ands the value obtained by inverting a specified bit of memory at the address indicated by (disp + rn) with the t bit, and stores the result in the t bit. the bit number is specified by 3-bit immediate data. with this instruction, data is read from memory as a byte unit. bandnot.b #imm3, @(disp12, rn) 70 & t t (disp+rn) specified by #imm3 inversion operation bandnotm (long d, long i, long n) /*bandnot.b #imm3, @(disp12, rn) */ { long disp, imm, temp, assignbit; disp = (0x00000fff & (long)d); imm= (0x00000007&(long)i); temp= (long) read_byte (r[n]+disp); assignbit =(0x00000001< section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 91 of 484 rej09b0051-0300 examples: bandnot.b #h'5,@(2,r0) ; before execution: @(r0 + 2) = h'20, t = 1 ; after execution: @(r0 + 2) = h'20, t = 0
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 92 of 484 rej09b0051-0300 6.3.3 bclr bit clear bit manipulation instruction bit clear SH-2A/sh2a-fpu (new) format abstract code cycle t bit bclr.b #imm3, @(disp12,rn) bclr #imm3, rn 0 ( of (disp+rn)) 0 of rn 0011nnnn0iii10010000dddddddddddd 10000110nnnn0iii 3 1 D D description clears a specified bit of memory at the address indicated by (disp + rn), or of the lsb 8 bits of a general register rn. the bit number is specified by 3-bit immediate data. with the bclr.b instruction, after data is read from memory as a byte unit, clearing of the specified bit is executed, and the resulting data is then written to memory as a byte unit. bclr.b #imm3, @(disp12, rn) 0 70 (disp+rn) specified by #imm3 bclr #imm3, rn rn 31 0 0 7 lower 8 bits specified by #imm3
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 93 of 484 rej09b0051-0300 operation bclrm (long d, long i, long n) /*bclr.b #imm3, @(disp12, rn) */ { long disp, imm, temp; disp = (0x00000fff & (long)d); imm= (0x00000007&(long)i); temp= (long) read_byte (r[n]+disp); temp&=(~(0x00000001< section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 94 of 484 rej09b0051-0300 6.3.4 bld bit load bit manipulation instruction bit load SH-2A/sh2a-fpu (new) format abstract code cycle t bit bld.b #imm3, @(disp12,rn) ( of (disp+rn)) t 0011nnnn0iii10010011dddddddddddd 3 operation result bld #imm3, rn of rn t 10000111nnnn1iii 1 operation result description stores a specified bit of memory at the address indicated by (disp + rn), or of the lsb 8 bits of a general register rn, in the t bit. the bit number is specified by 3-bit immediate data. with the bld.b instruction, data is read from memory as a byte unit. bld.b #imm3, @(disp12, rn) t 70 (disp+rn) specified by #imm3 bld #imm3, rn rn 31 lower 8 bits specified by #imm3 0 7 t
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 95 of 484 rej09b0051-0300 operation bldm (long d, long i, long n) /*bld.b #imm3, @(disp12, rn) */ { long disp, imm, temp,assignbit; disp = (0x00000fff & (long)d); imm= (0x00000007&(long)i); temp = (long) read_byte (r[n]+disp); assignbit=(0x00000001< section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 96 of 484 rej09b0051-0300 6.3.5 bldnot bit loadnot bit manipulation instruction bit not load SH-2A/sh2a-fpu (new) format abstract code cycle t bit bldnot.b #imm3, @(disp12,rn) ~ ( of (disp+rn)) t 0011nnnn0iii10011011dddddddddddd 3 operation result description inverts a specified bit of memory at the address indicated by (disp + rn), and stores the resulting value in the t bit. the bit number is specified by 3-bit immediate data. with the bldnot.b instruction, data is read from memory as a byte unit. bldnot.b #imm3, @(disp12, rn) t 70 (disp+rn) specified by #imm3 inversion operation bldnotm (long d, long i, long n) /*bldnot.b #imm3, @(disp12, rn) */ { long disp, imm, temp,assignbit; disp = (0x00000fff & (long)d); imm= (0x00000007&(long)i); temp = (long) read_byte (r[n]+disp); assignbit=(0x00000001< section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 97 of 484 rej09b0051-0300 examples: bldnot.b #h'5,@(2,r0) ; before execution: @(r0 + 2) = h'20, t = 1 ; after execution: @(r0 + 2) = h'20, t = 0
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 98 of 484 rej09b0051-0300 6.3.6 bor bit or bit manipulation instruction bit logical or SH-2A/sh2a-fpu (new) format abstract code cycle t bit bor.b #imm3, @(disp12,rn) ( of (disp+rn)) ? t t 0011nnnn0iii10010101dddddddddddd 3 operation result description ors a specified bit in memory at the address indicated by (disp + rn) with the t bit, and stores the result in the t bit. the bit number is specified by 3-bit immediate data. with this instruction, data is read from memory as a byte unit. bor.b #imm3, @(disp12, rn) 70 | t t (disp+rn) specified by #imm3
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 99 of 484 rej09b0051-0300 operation borm (long d, long i, long n) /*bor.b #imm3, @(disp12, rn) */ { long disp, imm, temp, assignbit; disp = (0x00000fff & (long)d); imm= (0x00000007&(long)i); temp= (long) read_byte (r[n]+disp); assignbit =(0x00000001< section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 100 of 484 rej09b0051-0300 6.3.7 bornot bit ornot bit manipulation instruction bit not logical or SH-2A/sh2a-fpu (new) format abstract code cycle t bit bornot.b #imm3, @(disp12,rn) ~ ( of (disp+rn)) ? t t 0011nnnn0iii10011101dddddddddddd 3 operation result description ors the value obtained by inverting a specified bit of memory at the address indicated by (disp + rn) with the t bit, and stores the result in the t bit. the bit number is specified by 3-bit immediate data. with this instruction, data is read from memory as a byte unit. bornot.b #imm3, @(disp12, rn) 70 | t t (disp+rn) specified by #imm3 inversion
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 101 of 484 rej09b0051-0300 operation bornotm (long d, long i, long n) /*bornot.b #imm3, @(disp12, rn) */ { long disp, imm, temp, assignbit; disp = (0x00000fff & (long)d); imm= (0x00000007&(long)i); temp= (long) read_byte (r[n]+disp); assignbit =(0x00000001< section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 102 of 484 rej09b0051-0300 6.3.8 bset bit set bit manipulation instruction bit set SH-2A/sh2a-fpu (new) format abstract code cycle t bit bset.b #imm3, @(disp12,rn) bset #imm3, rn 1 ( of (disp+rn)) 1 of rn 0011nnnn0iii10010001dddddddddddd 10000110nnnn1iii 3 1 ? ? description sets to 1 a specified bit of memory at the address indicated by (disp + rn), or of the lsb 8 bits of a general register rn. the bit number is specified by 3-bit immediate data. with the bset.b instruction, after data is read from memory as a byte unit, the specified bit is set to 1, and the resulting data is then written to memory as a byte unit. bset.b #imm3, @(disp12, rn) 1 70 (disp+rn) specified by #imm3 bset #imm3, rn rn 31 lower 8 bits specified by #imm3 1 0 7
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 103 of 484 rej09b0051-0300 operation bsetm (long d, long i, long n) /*bset.b #imm3, @(disp12, rn) */ { long disp, imm, temp; disp = (0x00000fff & (long)d); imm= (0x00000007&(long)i); temp= (long) read_byte (r[n]+disp); temp|=(0x00000001< section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 104 of 484 rej09b0051-0300 6.3.9 bst bit store bit manipulation instruction bit store SH-2A/sh2a-fpu (new) format abstract code cycle t bit bst.b #imm3, @(disp12,rn) bst #imm3, rn t ( of (disp+rn)) t of rn 0011nnnn0iii10010010dddddddddddd 10000111nnnn0iii 3 1 D D description transfers the contents of the t bit to a specified 1-bit location of memory at the address indicated by (disp + rn), or of the lsb 8 bits of a general register rn. the bit number is specified by 3-bit immediate data. with the bst.b instruction, after data is read from memory as a byte unit, transfer from the t bit to the specified bit is executed, and the resulting data is then written to memory as a byte unit. bst.b #imm3, @(disp12, rn) t 70 (disp+rn) specified by #imm3 bst #imm3, rn rn 31 lower 8 bits specified by #imm3 0 7 t
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 105 of 484 rej09b0051-0300 operation bstm (long d, long i, long n) /*bst.b #imm3, @(disp12, rn) */ { long disp, imm, temp; disp = (0x00000fff & (long)d); imm= (0x00000007&(long)i); temp = (long) read_byte (r[n]+disp); if(t==0) temp&=(~(0x00000001< section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 106 of 484 rej09b0051-0300 6.3.10 bxor bit exclusive or bit manipulation instruction bit exclusive logical or SH-2A/sh2a-fpu (new) format abstract code cycle t bit bxor.b #imm3, @(disp12,rn) ( of (disp+rn)) ^ t t 0011nnnn0iii10010110dddddddddddd 3 operation result description exclusive-ors a specified bit in memory at the address indicated by (disp + rn) with the t bit, and stores the result in the t bit. the bit number is specified by 3-bit immediate data. with this instruction, data is read from memory as a byte unit. bxor.b #imm3, @(disp12, rn) 70 ^ t t (disp+rn) specified by #imm3
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 107 of 484 rej09b0051-0300 operation bxorm (long d, long i, long n) /*bxor.b #imm3, @(disp12, rn) */ { long disp, imm, temp, assignbit; disp = (0x00000fff & (long)d); imm= (0x00000007&(long)i); temp= (long) read_byte (r[n]+disp); assignbit =(0x00000001< section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 108 of 484 rej09b0051-0300 6.3.11 clips clip as signed arithmetic instruction signed saturation value compare instruction SH-2A/sh2a-fpu (new) no. format abstract code cycle t bit 1 clips.b rn if rn > (saturation upper-limit value), (saturation upper-limit value) rn, 1 cs 0100nnnn10010001 1 D 2 clips.w rn if rn < (saturation lower-limit value), (saturation lower-limit value) rn, 1 cs 0100nnnn10010101 1 D description determines saturation. signed data is used with this instruction. the saturation upper-limit value is stored in general register rn if the contents of rn exceed the saturation upper-limit value, or the saturation lower-limit value is stored in rn if the contents of rn are less than the saturation lower- limit value, and the cs bit is set to 1. the saturation upper-limit value and lower-limit value for each instruction are shown in the table below. no. instruction saturation lower-limit value saturation upper-limit value 1 clips.b rn h'ffffff80 h'0000007f 2 clips.w rn h'ffff8000 h'00007fff notes the cs bit value does not change if the contents of general register rn do not exceed the saturation upper-limit value or are not less than the saturation lower-limit value.
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 109 of 484 rej09b0051-0300 operation clipsb(long n) /* clips.b rn*/ { if ( r[n] > 0x0000007f) { r[n]=0x0000007f; cs=1; } else if (r[n] < 0xffffff80) { r[n]=0xffffff80; cs=1; } pc+2; } clipsw(long n) /* clips.w rn*/ { if ( r[n] > 0x00007fff) { r[n]=0x00007fff; cs=1; } else if (r[n] < 0xffff8000) { r[n]=0xffff8000; cs=1; pc+2; }
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 110 of 484 rej09b0051-0300 examples: clips.b r0 ; before execution: r0 = h'0000000f, cs = 0 ; after execution: r0 = h'0000000f, cs = 0 clips.b r1 ; before execution: r1 = h'00000080, cs = 0 ; after execution: r1 = h'0000007e, cs = 1 clips.w r0 ; before execution: r0 = h'fffffff0, cs = 0 ; after execution: r0 = h'fffffff0, cs = 0 clips.w r1 ; before execution: r1 = h'ffff7000, cs = 0 ; after execution: r1 = h'ffff8000, cs = 1
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 111 of 484 rej09b0051-0300 6.3.12 clipu clip as unsigned arithmetic instruction unsigned saturation value compare instruction SH-2A/sh2a-fpu (new) no. format abstract code cycle t bit 1 clipu.b rn 0100nnnn10000001 1 D 2 clipu.w rn if rn > (saturation value), (saturation value) rn, 1 cs 0100nnnn10000101 1 D description determines saturation. unsigned data is used with this instruction. if the contents of general register rn exceed the saturation value, the saturation value is stored in rn and the cs bit is set to 1. the saturation value for each instruction is shown in the table below. no. instruction saturation value 1 clipu.b rn h'000000ff 2 clipu.w rn h'0000ffff notes the cs bit value does not change if the contents of general register rn do not exceed the saturation upper-limit value.
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 112 of 484 rej09b0051-0300 operation clipub(long n) /* clipu.b rn*/ { if ( r[n] > 0x000000ff) { r[n]=0x000000ff; cs=1; } pc+2; } clipuw(long n) /* clipu.w rn*/ { if ( r[n] > 0x0000ffff) { r[n]=0x0000ffff; cs=1; } pc+2; } examples: clipu.b r0 ; before execution: r0 = h'0000000f, cs = 0 ; after execution: r0 = h'0000000f, cs = 0 clipu.b r1 ; before execution: r1 = h'00000100, cs = 0 ; after execution: r1 = h'000000ff, cs = 1 clipu.w r0 ; before execution: r0 = h'00000fff, cs = 0 ; after execution: r0 = h'00000fff, cs = 0 clipu.w r1 ; before execution: r1 = h'00010000, cs = 0 ; after execution: r1 = h'0000ffff, cs = 1
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 113 of 484 rej09b0051-0300 6.3.13 divs divide as signed arithmetic instruction signed division SH-2A/sh2a-fpu (new) format abstract code cycle t bit divs r0,rn signed, rn r0 rn 0100nnnn10010100 36 D description executes division of the 32-bit contents of a general register rn (dividend) by the contents of r0 (divisor). this instruction executes signed division and finds the quotient only. a remainder operation is not provided. to obtain the remainder, find the product of the divisor and the obtained quotient, and subtract this value from the dividend. the sign of the remainder will be the same as that of the dividend. notes an overflow exception will occur if the negative maximum value (h'00000000) is divided by ?1. if division by zero is performed a division by zero exception will occur. if an interrupt is generated while this instruction is being executed, execution will be halted. the return address will be the start address of this instruction, and this instruction will be re-executed. operation divs (long n) /* divs r0, rn */ { r[n]=r[n] / r[0]; pc+=2; } examples: divs r0,r1 ; r1(32bits) / r0 (32bits) = r1(32bits); signed
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 114 of 484 rej09b0051-0300 6.3.14 divu divide as unsigned arithmetic instruction unsigned division SH-2A/sh2a-fpu (new) format abstract code cycle t bit divu r0, rn unsigned, rn r0 rn 0100nnnn10000100 34 D description executes division of the 32-bit contents of a general register rn (dividend) by the contents of r0 (divisor). this instruction executes unsigned division and finds the quotient only. a remainder operation is not provided. to obtain the remainder, find the product of the divisor and the obtained quotient, and subtract this value from the dividend. notes a division by zero exception will occur if division by zero is performed. if an interrupt is generated while this instruction is being executed, execution will be halted. the return address will be the start address of this instruction, and this instruction will be re-executed. operation divu (long n) /* divu r0, rn */ { (unsigned long) r[n]= (unsigned long)r[n] / (unsigned long )r[0]; pc+=2; } examples: divu r0,r1 ; r1(32bits) / r0(32bits) = r1(32bits); unsigned
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 115 of 484 rej09b0051-0300 6.3.15 fmov floating-point move floating-point instruction floating-point transfer SH-2A/sh2a-fpu (new) no. sz format abstract code cycle t bit 1 2 3 4 0 1 0 1 fmov.s frm, @(disp12,rn) fmov.d drm, @(disp12,rn) fmov.s @(disp12,rm), frn fmov.d @(disp12,rm), drn frm (disp4+rn) drm (disp8+rn) (disp4+rm) frn (disp8+rm) drn 0011nnnnmmmm00010011dddddddddddd 0011nnnnmmm000010011dddddddddddd 0011nnnnmmmm00010111dddddddddddd 0011nnn0mmmm00010111dddddddddddd 1 2 1 2 D D D D description 1. transfers frm contents to memory at the address indicated by (disp + rn). 2. transfers drm contents to memory at the address indicated by (disp + rn). 3. transfers memory contents at the address indicated by (disp + rn) to frn. 4. transfers memory contents at the address indicated by (disp + rn) to drn. note for the renesas technology super h risc engine assembler, declarations should use scaled values (4, 8) as displacement values. operation void fmov_index_disp12_store(int m,n) /*fmov.s frm, @(disp12,rn) */ { long disp; disp = (0x00000fff & (long)d); write_int ( r[n]+(disp<<2), fr[m]); pc +=4; } void fmov_index_disp12_store_dr(int m,n) /*fmov.d drm, @(disp12,rn) */ { long disp; disp = (0x00000fff & (long)d);
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 116 of 484 rej09b0051-0300 write_quad (r[n]+(disp<<3), dr[m>>1]); pc +=4; } void fmov_index_disp12_load(int m,n) /*fmov.s @(disp12,rm), frn */ { long disp; disp = (0x00000fff & (long)d); fr[n] = read_int (r[m]+(disp<<2)); pc +=4; } void fmov_index_disp12_load_dr(int m,n) /*fmov.d @(disp12,rm), drn */ { long disp; disp = (0x00000fff & (long)d); dr[n>>1] = read_quad (r[m]+(disp<<3)); pc +=4; }
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 117 of 484 rej09b0051-0300 examples: fmov.s fr0,@(2,r2) ; before execution: fr0 = h'12345670 ; after execution: @(r2 + 8) = h'12345670 fmov.d dr0,@(2,r2) ; before execution: fr0 = h'01234567 fr1 = h'89abcdef ; after execution: @(r2 + 16) = h'01234567 @(r2 + 20) = h'89abcdef fmov.s @(2,r2),fr0 ; before execution: @(r2 + 8) = h'12345670 ; after execution: fr0 = h'12345670 fmov.d @(2,r2),dr0 ; before execution: @(r2 + 16) = h'01234567 @(r2 + 20) = h'89abcdef ; after execution: fr0 = h'01234567 fr1 = h'89abcdef
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 118 of 484 rej09b0051-0300 6.3.16 jsr/n jump to subroutine with no delay slot branch instruction branch to subroutine procedure with no delay slot SH-2A/sh2a-fpu (new) format abstract code cycle t bit jsr/n @rm jsr/n @@(disp8, tbr) pc - 2 pr, rm pc pc - 2 pr, (disp4+tbr) pc 0100mmmm01001011 10000011dddddddd 3 5 D D description branches to a subroutine procedure at the designated address. the contents of pc are stored in pr and execution branches to the address indicated by the contents of general register rm as 32-bit data or to the address read from memory address (disp 4 + tbr). the stored contents of pc indicate the starting address of the second instruction after the present instruction. this instruction is used with rts as a subroutine procedure call. notes this is not a delayed branch instruction. for the renesas technology super h risc engine assembler, declarations should use scaled values (4) as displacement values.
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 119 of 484 rej09b0051-0300 operation jsrn (long m) /* jsr/n @rm, */ { unsigned long temp; temp=pc; pr=pc-2; pc=r[m]+4; } jsrnm (long d ) /* jsr/n @@(disp8, tbr) */ { unsigned long temp; long disp; temp=pc; pr=pc-2; disp=(0x000000ff & d); pc=read_long(tbr+(disp<<2))+4; }
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 120 of 484 rej09b0051-0300 examples: mov.l jsrn_table,r0 ; r0 = trget address jsr/n @r0 ; branch to trget. add r0,r1 ; procedure return destination (pr contents) . . . . . . . . . align 4 jsrn_table: .data.1 trget ; jump table trget: nop ; entry to procedure mov r2,r3 ; rts/n ; return to above add instruction. tbr+h?08 .data.1 ffff7f80 ; . . . . . . . . jsr/n @@(2,tbr) ; branch to address stored in address tbr + h'08 add r0,r1 ; procedure return destination (pr contents) . . . . . . . . ffff7f80 nop ; entry to procedure ffff7f82 mov r2,r3 ; ffff7f84 rts/n ; return to above add instruction.
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 121 of 484 rej09b0051-0300 6.3.17 ldbank load register bank system control instruction transfer to specified register bank entry SH-2A/sh2a-fpu (new) format abstract code cycle t bit ldbank @rm, r0 (specified register bank entry) r0 0100mmmm11100101 6 D description the register bank entry indicated by the contents of general register rm is transferred to general register r0. the register bank number and register stored in the bank are specified by general register rm. bank 0 bank 1 bank 2 bank 3 bank 4 bank 5 bank 6 bank 7 bank 8 bank 9 bank 10 bank 11 bank 12 bank 13 bank 14 000000000 000000001 000000010 000000011 000000100 000000101 000000110 000000111 000001000 000001001 000001010 000001011 000001100 000001101 000001110 r0 r1 r2 r3 r4 r5 r6 r7 r8 r9 r10 r11 r12 r13 r14 mach interrupt vector offset pr gbr macl 00000 00001 00010 00011 00100 00101 00110 00111 01000 01001 01010 01011 01100 01101 01110 01111 10000 10001 10010 10011 bn en 00 2 1 0 7 6 16 15 0 31 (rm) 0 ................................... bn en register bank entry in register bank bn: bank number field en: entry number field
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 122 of 484 rej09b0051-0300 note the architecture supports a maximum of 512 banks. however, the number of banks differs depending on the product. operation ldbank (long m) /*ldbank @rm, r0 */ { r[0]=read_bank_long(r[m]); pc+=2; } examples: ldbank @r1,r0 ; before execution: r1 = h'00000108 ; after execution: r0 = contents of r2 stored in r0 = bank 2
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 123 of 484 rej09b0051-0300 6.3.18 ldc load to control register system control instruction load to control register SH-2A/sh2a-fpu (new) format abstract code cycle t bit ldc rm, tbr rm tbr 0100mmmm01001010 1 D description stores a source operand in control register tbr. operation ldctbr (long m) /* ldc rm, tbr*/ { tbr=r[m]; pc+=2; } examples: ldc r0,tbr ; before execution: r0 = h'12345678, tbr = h'00000000 ; after execution: tbr = h'12345678
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 124 of 484 rej09b0051-0300 6.3.19 mov move structure data data transfer instruction structure data transfer SH-2A/sh2a-fpu (new) format abstract code cycle t bit mov.b rm, @(disp12,rn) rm (disp+rn) 0011nnnnmmmm00010000dddddddddddd 1 D mov.w rm, @(disp12,rn) rm (disp2+rn) 0011nnnnmmmm00010001dddddddddddd 1 D mov.l rm, @(disp12,rn) rm (disp4+rn) 0011nnnnmmmm00010010dddddddddddd 1 D mov.b @(disp12,rm), rn (disp+rm) sign extension rn 0011nnnnmmmm00010100dddddddddddd 1 D mov.w @(disp12,rm), rn (disp2+rm) sign extension rn 0011nnnnmmmm00010101dddddddddddd 1 D mov.l @(disp12,rm), rn (disp4+rm) rn 0011nnnnmmmm00010110dddddddddddd 1 D description transfers a source operand to a destination. this instruction is ideal for data access in a structure or the stack. note for the renesas technology super h risc engine assembler, declarations should use scaled values (1, 2, 4) as displacement values. operation movbs12 (long d, long m, long n) /* mov.b rm, @(disp12,rn) */ { long disp; disp = (0x00000fff & (long)d); write_byte(r[n]+disp,r[m]); pc+=4; } movws12 (long d, long m, long n) /* mov.w rm, @(disp12,rn) */ { long disp; disp = (0x00000fff & (long)d);
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 125 of 484 rej09b0051-0300 write_word(r[n]+(disp<<1),r[m]); pc+=4; } movls12 (long d, long m, long n) /* mov.l rm, @(disp12,rn) */ { long disp; disp = (0x00000fff & (long)d); write_long(r[n]+(disp<<2), r[m]); pc+=4; } movbl12 (long d, long m, long n) /* mov.b @(disp12,rm), rn */ { long disp; disp = (0x00000fff & (long)d); r[n]=read_byte(r[m]+disp); if ( ( r[n]&0x80 ) ==0) r[n] &=0x000000ff; else r[0] |=0xffffff00; pc+=4; } movwl12 (long d, long m, long n) /* mov.w @(disp12,rm), rn */ { long disp; disp = (0x00000fff & (long)d); r[n]=read_word(r[m]+(disp<<1)); if ((r[n]&0x8000) ==0) r[n] &=0x0000ffff; else r[n]|=0xffff0000; pc+=4; }
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 126 of 484 rej09b0051-0300 movll12 (long d, long m, long n) /* mov.l @(disp12,rm), rn */ { long disp; disp = (0x00000fff & (long)d); r[n]=read_long(r[m]+(disp<<2)); pc+=4; } examples: mov.b r0,@(1,r1) ; before execution: r0 = h'ffff7f80 ; after execution: @(r1 + 1) = h'80 mov.l @(2,r0),r1 ; before execution: @(r0 + 8) = h'12345670 ; after execution: r1 = h'12345670
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 127 of 484 rej09b0051-0300 6.3.20 mov move reverse stack data transfer instruction reverse stack transfer SH-2A/sh2a-fpu (new) format abstract code cycle t bit mov.b r0, @rn+ r0 (rn), rn + 1 rn 0100nnnn10001011 1 D mov.w r0, @rn+ r0 (rn), rn + 2 rn 0100nnnn10011011 1 D mov.l r0, @rn+ r0 (rn), rn + 4 rn 0100nnnn10101011 1 D mov.b @-rm, r0 rm - 1 rm (rm) sign extension r0 0100mmmm11001011 1 D mov.w @-rm, r0 rm - 2 rm (rm) sign extension r0 0100mmmm11011011 1 D mov.l @-rm, r0 rm - 4 rm (rm) r0 0100mmmm11101011 1 D description transfers a source operand to a destination. operation movrsbp (long n) /* mov.b r0, @rn+*/ { write_byte(r[n], r[0]); r[n]+=1; pc+=2; } movrswp (long n) /* mov.w r0, @rn+*/ { write_word(r[n], r[0]); r[n]+=2; pc+=2; }
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 128 of 484 rej09b0051-0300 movrslp (long n) /* mov.l r0, @rn+*/ { write_long(r[n], r[0]); r[n]+=4; pc+=2; } movrsbm (long m) /* mov.b @-rm, r0*/ { r[m]-=1; r[0]=(long) read_word (r[m]); if ((r[0]&0x80)==0) r[0]&=0x000000ff; else r[0] |=0xffffff00; pc+=2; } movrswm (long m) /* mov.w @-rm, r0*/ { r[m]-=2; r[0]=(long) read_word (r[m]); if ((r[0]&0x8000)==0) r[0]&=0x0000ffff; else r[0] |=0xffff0000; pc+=2; } movrslm(long m) /* mov.l @-rm, r0*/ { r[m]-=4; r[0]=read_long (r[m]); pc+=2; }
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 129 of 484 rej09b0051-0300 examples: mov.b r0, @r1+ ; before execution: r0 = h'aaaaaaaa, r1 = ffff7f80 ; after execution: r1 = h'ffff7f81, @(h?ffff7f80) = h'aa mov.l @-r1, r0 ; before execution: r1 = h'12345678 ; after execution: r1 = h'12345674, r0 = @(h'12345674)
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 130 of 484 rej09b0051-0300 6.3.21 movi20 move immediate 20bits data data transfer instruction 20-bit immediate data transfer SH-2A/sh2a-fpu (new) format abstract code cycle t bit movi20 #imm20, rn imm sign extension rn 0000nnnniiii0000iiiiiiiiiiiiiiii 1 D description stores immediate data that has been sign-extended to longword in general register rn. imm rn 20 bits 19 0 31 sign extension movi20 20 bits 19 0 operation movi20 (long i, long n) /* movi20 #imm, rn */ { if (i&0x00080000) ==0) r[n]= (0x000fffff & (long) i); else r[n]=(0xfff00000 | (long) i); pc+=4; } examples: movi20 h'7ffff,r0 ; before execution: r0 = h'00000000 ; after execution: r0 = h'0007ffff
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 131 of 484 rej09b0051-0300 6.3.22 movi20s move immediate 20bits data and 8bits shift left data transfer instruction 20-bit immediate data transfer and 8-bit left-shift SH-2A/sh2a-fpu (new) format abstract code cycle t bit movi20s #imm20, rn imm<<8 sign extension rn 0000nnnniiii0001iiiiiiiiiiiiiiii 1 D description shifts immediate data 8 bits to the left and performs sign extension to longword, then stores the resulting data in general register rn. using an or or add instruction as the next instruction enables a 28-bit absolute address to be generated. see section appendix b, programming guidelines, for details. imm rn 20 bits 27 0 31 sign extension 8 00000000 movi20s 20 bits 19 0 note for the renesas technology super h risc engine assembler, declarations should use immediate data that has been shifted 8 bits to the left.
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 132 of 484 rej09b0051-0300 operation movi20s (long i, long n) /* movi20s #imm, rn */ { if (i&0x00080000) ==0) r[n]= (0x000fffff & (long) i); else r[n]=(0xfff00000 | (long) i); r[n]<<=8; pc+=4; } examples: movi20s h'7ffff,r0 ; before execution: r0 = h'00000000 ; after execution: r0 = h'07ffff00
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 133 of 484 rej09b0051-0300 6.3 . 23 movml.l move multi-register lower part data transfer instruction r0-rn register save/restore instruction SH-2A/sh2a-fpu (new) format abstract code cycle t bit movml.l rm, @-r15 r15 - 4 r15, rm (r15) r15 - 4 r15, rm - 1 (r15) : r15 - 4 r15, r0 (r15) note: when rm = r15, read rm as pr 0100mmmm11110001 1 to 16 D movml.l @r15+, rn (r15) r0, r15 + 4 r15 (r15) r1, r15 + 4 r15 : (r15) rn, r15 + 4 r15 note: when rn = r15, read rn as pr 0100nnnn11110101 1 to 16 D description transfers a source operand to a destination. this instruction performs transfer between a number of general registers (r0 to rn/rm) not exceeding the specified register number and memory with the contents of r15 as its address. if r15 is specified, pr is transferred instead of r15. that is, when nnnn( mmmm) = 1111 is specified, r0 to r14 and pr are the general registers subject to transfer. operation movlmml (long m) /*movml.l rm, @-r15*/ { long i; for (i=m; i 0; i--) { if (i==15) { write_long (r[15]-4, pr); r[15]-=4; } else
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 134 of 484 rej09b0051-0300 { write_long (r[15]-4, r[i]); r[15]-=4; } } pc+=2; } movlpml (long n) /*movml.l @r15+, rn */ { int i; for (i=0; i n; i++) { if (i==15) { pr=read_long (r[15]); } else { r[i] = read_long (r[15]); } r[15]+=4; } pc+=2; }
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 135 of 484 rej09b0051-0300 examples: movml. l r7,@-r15 ; before execution: r15 = h'ffff7f80 r0 = h'00000000, r1 = h'11111111 r2 = h'22222222, r3 = h'33333333 r4 = h'44444444, r5 = h'55555555 r6 = h'66666666, r7 = h'77777777 ; after execution: r15 = h'ffff7f60 @(h'ffff7f7c) = h'77777777 @(h'ffff7f78) = h'66666666 @(h'ffff7f74) = h'55555555 @(h'ffff7f70) = h'44444444 @(h'ffff7f6c) = h'33333333 @(h'ffff7f68) = h'22222222 @(h'ffff7f64) = h'11111111 @(h'ffff7f60) = h'00000000 movml. l @r15+,r7 ; before execution: r15 = h'ffff7f60 @(h'ffff7f60) = h'00000000 @(h'ffff7f64) = h'11111111 @(h'ffff7f68) = h'22222222 @(h'ffff7f6c) = h'33333333 @(h'ffff7f70) = h'44444444 @(h'ffff7f74) = h'55555555 @(h'ffff7f78) = h'66666666 @(h'ffff7f7c) = h'77777777 ; after execution: r15 = h'ffff7f80 r0 = h'00000000, r1 = h'11111111 r2 = h'22222222, r3 = h'33333333 r4 = h'44444444, r5 = h'55555555 r6 = h'66666666, r7 = h'77777777
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 136 of 484 rej09b0051-0300 6.3.24 movmu.l move multi-register upper part data transfer instruction rn-r14, pr register save/restore instruction SH-2A/sh2a-fpu (new) format abstract code cycle t bit movmu.l rm, @-r15 r15 - 4 r15, pr (r15) r15 - 4 r15, r14 (r15) : r15 - 4 r15, rm (r15) note: when rm = r15, read rm as pr 0100mmmm11110000 1 to 16 D movmu.l @r15+, rn (r15) rn, r15 + 4 r15 (r15) rn + 1, r15 + 4 r15 : (r15) r14, r15 + 4 r15 (r15) pr, r15 + 4 r15 note: when rn = r15, read rn as pr 0100nnnn11110100 1 to 16 D description transfers a source operand to a destination. this instruction performs transfer between a number of general registers (rn/rm to r14, pr) not lower than the specified register number and memory with the contents of r15 as its address. if r15 is specified, pr is transferred instead of r15. operation movlmmu (long m) /*movmu.l rm, @-r15 */ { int i; write_long (r[15]-4, pr); r[15]-=4; for (i = 14; i m; i--) { write_long (r[15]-4, r[i]); r[15]-=4; }
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 137 of 484 rej09b0051-0300 pc+=2; } movlpmu (long n) /*movmu.l @r15+, rn*/ { int i; for (i=n; i 14; i++) { r[i] = read_long (r[15]); r[15]+=4; } pr=read_long (r[15]); r[15]+=4; pc+=2; }
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 138 of 484 rej09b0051-0300 examples: movmu. l r8,@-r15 ; before execution: r15 = h'ffff7f80 r8 = h'88888888, r9 = h'99999999 r10 = h'aaaaaaaa, r11 = h'bbbbbbbb r12 = h'cccccccc, r13 = h'dddddddd r14 = h'eeeeeeee, pr = h'fffffff0 ; after execution: r15 = h'ffff7f60 @(h'ffff7f7c) = h'fffffff0 @(h'ffff7f78) = h'eeeeeeee @(h'ffff7f74) = h'dddddddd @(h'ffff7f70) = h'cccccccc @(h'ffff7f6c) = h'bbbbbbbb @(h'ffff7f68) = h'aaaaaaaa @(h'ffff7f64) = h'99999999 @(h'ffff7f60) = h'88888888 movmu. l @r15+,r8 ; before execution: r15 = h'ffff7f60 @(h'ffff7f60) = h'88888888 @(h'ffff7f64) = h'99999999 @(h'ffff7f68) = h'aaaaaaaa @(h'ffff7f6c) = h'bbbbbbbb @(h'ffff7f70) = h'cccccccc @(h'ffff7f74) = h'dddddddd @(h'ffff7f78) = h'eeeeeeee @(h'ffff7f7c) = h'fffffff0 ; after execution: r15 = h'ffff7f80 r8 = h'88888888, r9 = h'99999999 r10 = h'aaaaaaaa, r11 = h'bbbbbbbb r12 = h'cccccccc, r13 = h'dddddddd r14 = h'eeeeeeee, pr = h'fffffff0
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 139 of 484 rej09b0051-0300 6.3.25 movrt move reverse tbit data transfer instruction t bit reverse rn transfer SH-2A/sh2a-fpu (new) format abstract code cycle t bit movrt rn ~ t rn 0000nnnn00111001 1 D description reverses the t bit and then stores the resulting value in general register rn. the value of rn is 0 when t = 1 and 1 when t = 2. operation movrt (long n) /*movrt rn */ { if (t ==1) r[n]=0x00000000; else r[n] = 0x00000001; pc+=2; } examples: xor r2,r2 ; r2 = 0 cmp/pz r2 ; t = 1 movrt r0 ; r0 = 0 clrt ; t = 0 movrt r1 ; r1 = 1
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 140 of 484 rej09b0051-0300 6.3.26 movu move structure data as unsigned data transfer instruction structure data unsigned transfer SH-2A/sh2a-fpu (new) format abstract code cycle t bit movu.b @(disp12,rm), rn (disp+rm) zero extension rn 0011nnnnmmmm00011000dddddddddddd 1 D movu.w @(disp12,rm), rn (disp2+rm) zero extension rn 0011nnnnmmmm00011001dddddddddddd 1 D description transfers a source operand to a destination, performing unsigned data transfer. this instruction is ideal for data access in a structure or the stack. note for the renesas technology super h risc engine assembler, declarations should use scaled values (1, 2) as displacement values.
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 141 of 484 rej09b0051-0300 operation movbul12 (long d, long m, long n) /* movu.b @(disp12,rm), rn */ { long disp; disp = (0x00000fff & (long)d); r[n]=read_byte(r[m]+disp); r[n] &=0x000000ff; pc+=4; } movwul12 (long d, long m, long n) /* movu.w @(disp12,rm), rn */ { long disp; disp = (0x00000fff & (long)d); r[n]=read_word(r[m]+(disp<<1)); r[n] &=0x0000ffff; pc+=4; } examples: movu.b @(2,r0),r1 ; before execution: @(r0 + 2) = h'ff ; after execution: r1 = h'000000ff movu.w @(2,r0),r1 ; before execution: @(r0 + 4) = h'ffff ; after execution: r1 = h'0000ffff
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 142 of 484 rej09b0051-0300 6.3.27 mulr multiply to register arithmetic instruction rn result storage signed multiplication SH-2A/sh2a-fpu (new) format abstract code cycle t bit mulr r0,rn r0 rn rn 0100nnnn10000000 2 D description performs 32-bit multiplication of the contents of general register r0 by rn, and stores the lower 32 bits of the result in general register rn. operation mulr (long n) /* mulr r0, rn */ { r[n] = r[0]*r[n]; pc+=2; } examples: mulr r0,r1 ; before execution: r0 = h'fffffffe, r1 = h'00005555 ; after execution: r1 = h'ffff5556
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 143 of 484 rej09b0051-0300 6.3.28 nott not tbit data transfer instruction t bit inversion and transfer SH-2A/sh2a-fpu (new) format abstract code cycle t bit nott ~ t t 0000000001101000 1 operation result description inverts the t bit, then stores the resulting value in the t bit. operation nott (long n ) /*nott rn */ { if (t ==1) t=0; else t=1; pc+=2; } examples: sett ;t = 1 nott ;t = 0 nott ;t = 1
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 144 of 484 rej09b0051-0300 6.3.29 pref prefetch data to cache data transfer instruction prefetch to data cache SH-2A/sh2a-fpu (new) format abstract code cycle t bit pref @rn prefetch cache block 0000nnnn10000011 1 D description reads a 16-byte data block starting at a 16-byte boundary into the operand cache. address related errors are not generated for this instruction. in the event of an error, this instruction is handled as an nop (no operation) instruction. note on products with no cache, this instruction is handled as a nop instruction. operation pref (long n) /* pref @rn */ { pc+=2; } examples: mov.l soft_pf,r1 ; r1 address is soft_pf pref @r1 ; load soft_pf data into internal data cache . align 16 soft_pf: .data.w h'1234 .data.w h'5678 .data.w h'9abc .data.w h'def0
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 145 of 484 rej09b0051-0300 6.3.30 resbank restore from registerbank system control instruction register restoration from register bank SH-2A/sh2a-fpu (new) format abstract code cycle t bit resbank restoration from register bank 0000000001011011 9 * D note: * 19 when a bank overflow has occurred and the register is restored from the stack description restores the last register saved to a register bank. operation resbank( ) /*resbank */ /*m = (number of register bank to which a save was last performed)*/ { int m; if(bo==0) { pr = register_bank[m].pr_bank; gbr = register_bank[m].gbr_bank; macl = register_bank[m].macl_bank; mach = register_bank[m].mach_bank; for (i=14; i 14; i++) i 0; i-- { r[i] = register_bank[m].r_bank[i]; } } else { for (i=0; i 14; i++) { r[i] = read_long(r[15]); r[15]+=4;
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 146 of 484 rej09b0051-0300 } pr=read_long(r[15]); r[15]+=4; gbr=read_long(r[15]); r[15]+=4; mach=read_long(r[15]); r[15]+=4; macl =read_long(r[15]); r[15]+=4; } pc+=2; } examples: resbank ; recover register from register bank. rte ; return to original routine. add #8,r14 ; executed before branch.
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 147 of 484 rej09b0051-0300 6.3.31 rts/n return from subroutine with no delay slot branch instruction return from subroutine procedure with no delay slot SH-2A/sh2a-fpu (new) format abstract code cycle t bit rts/n pr pc 0000000001101011 3 D description performs a return from a subroutine procedure. that is, the pc is restored from pr, and processing is resumed from the address indicated by the pc. this instruction enables a return to be made from a subroutine procedure called by a bsr or jsr instruction to the origin of the call. note this is not a delayed branch instruction. operation rtsn ( ) /* rts/n */ { pc=pr+4; } examples: mov.l table,r3 ; r0 = trget address jsr/n @r3 ; branch to trget. add r0,r1 ; procedure return destination (pr contents) . . . . . . . . table: .data.1 trget ; jump table . . . . . . . . trget: nop ; entry to procedure mov r2,r3 ; rts/n ; return to above add instruction.
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 148 of 484 rej09b0051-0300 6.3.32 rtv/n return to value and from subroutine with no delay slot branch instruction return from subroutine procedure with register value transfer and with no delay slot SH-2A/sh2a-fpu (new) format abstract code cycle t bit rtv/n rm rm r0, pr pc 0000mmmm01111011 3 D description performs a return from a subroutine procedure after a transfer from specified general register rm to r0. that is, after the rm value is stored in r0, the pc is restored from pr, and processing is resumed from the address indicated by the pc. this instruction enables a return to be made from a subroutine procedure called by a bsr or jsr instruction to the origin of the call. note this is not a delayed branch instruction. operation rtvn (int m) /* rtv/n rm */ { r[0]=r[m]; pc=pr+4; }
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 149 of 484 rej09b0051-0300 examples: mov.l table,r3 ; r0 = trget address jsr/n @r3 ; branch to trget. add r0,r1 ; procedure return destination (pr contents) . . . . . . . . table: .data.1 trget ; jump table . . . . . . . . trget: nop ; entry to procedure mov #12,r3 ; r3 = h'00000012 rtv/n r3 ; return to above add instruction. ; r0 = h'00000012
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 150 of 484 rej09b0051-0300 6.3.33 shad shift arithmetic dynamically shift instruction dynamic arithmetic shift format abstract code cycle t bit shad rm, rn when rm 0, rn<>|rm| [msb rn] 0100nnnnmmmm1100 1 D description shifts the contents of general register rn arithmetically. general register rm specifies the shift direction and number of bits to be shifted. a left shift is performed when the rm register value is positive, and a right shift when negative. in a right shift, the msb is added at the upper end. the number of bits to be shifted is specified by the lower 5 bits (bits 4 to 0) of register rm. if the value is negative (msb = 1), the rm register value is expressed as a two's complement. therefore, the shift amount in a right shift is the value obtained by adding 1 to the inverse of the lower 5 bits of register rm. the shift amount is 0 to 31 in a left shift, and 1 to 32 in a right shift. msb lsb rm 0 0 msb lsb rm 0 msb
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 151 of 484 rej09b0051-0300 operation shad (int m,n) /* shad rm,rn */ { int sgn = r[m] & 0x80000000; if (sgn == 0) r[n] <<= (r[m] & 0x0000001f); else if ((r[m] & 0x0000001f) == 0) { if ((r[n] & 0x80000000) == 0) r[n] = 0; else r[n]=0xffffffff; } else r[n]=(long)r[n] >> ((~r[m] & 0x0000001f)+1); pc+=2; } examples: shad r1, r2 ; before execution: r1 = h'ffffffec, r2 = h'80180000 ; after execution: r1 = h'ffffffec, r2 = h'fffff801 shad r3, r4 ; before execution: r3 = h'00000014, r2 = h'fffff801 ; after execution: r3 = h'00000014, r2 = h'80100000
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 152 of 484 rej09b0051-0300 6.3.34 shld shift logical dynamically shift instruction dynamic logical shift format abstract code cycle t bit shld rm, rn when rm 0, rn<>|rm| [0 rn] 0100nnnnmmmm1101 1 D description shifts the contents of general register rn logically. general register rm specifies the shift direction and number of bits to be shifted. a left shift is performed when the rm register value is positive, and a right shift when negative. in a right shift, 0 is added at the upper end. the number of bits to be shifted is specified by the lower 5 bits (bits 4 to 0) of register rm. if the value is negative (msb = 1), the rm register value is expressed as a two's complement. therefore, the shift amount in a right shift is the value obtained by adding 1 to the inverse of the lower 5 bits of register rm. the shift amount is 0 to 31 in a left shift, and 1 to 32 in a right shift. msb lsb rm 0 0 msb lsb rm 0 0
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 153 of 484 rej09b0051-0300 operation shld (int m,n) /* shld rm,rn */ { int sgn = r[m] & 0x80000000; if (sgn == 0) r[n] <<= (r[m] & 0x0000001f); else if ((r[m] & 0x0000001f) == 0) r[n] = 0; else r[n]=(unsigned)r[n] >> ((~r[m] & 0x0000001f)+1); pc+=2; } examples: shld r1, r2 ; before execution: r1 = h'ffffffec, r2 = h'80180000 ; after execution: r1 = h'ffffffec, r2 = h'00000801 shld r3, r4 ; before execution: r3 = h'00000014, r2 = h'fffff801 ; after execution: r3 = h'00000014, r2 = h'80100000
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 154 of 484 rej09b0051-0300 6.3.35 stbank store register bank system control instruction register save to specified bank entry SH-2A/sh2a-fpu (new) format abstract code cycle t bit stbank r0, @rn r0 (specified register bank entry) 0100nnnn11100001 7 D description r0 is transferred to the register bank entry indicated by the contents of general register rn. the register bank number and register stored in the bank are specified by general register rn. bank 0 bank 1 bank 2 bank 3 bank 4 bank 5 bank 6 bank 7 bank 8 bank 9 bank 10 bank 11 bank 12 bank 13 bank 14 000000000 000000001 000000010 000000011 000000100 000000101 000000110 000000111 000001000 000001001 000001010 000001011 000001100 000001101 000001110 r0 r1 r2 r3 r4 r5 r6 r7 r8 r9 r10 r11 r12 r13 r14 mach interrupt vector offset pr gbr macl 00000 00001 00010 00011 00100 00101 00110 00111 01000 01001 01010 01011 01100 01101 01110 01111 10000 10001 10010 10011 bn en 00 2 1 0 7 6 16 15 0 31 (rn) 0 ................................... bn en register bank entry in register bank bn: bank number field en: entry number field
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 155 of 484 rej09b0051-0300 note the architecture supports a maximum of 512 banks. however, the number of banks differs depending on the product. operation stbank (long n) /*stbank r0, @rn */ { write_bank_long (r[n], r[0]) pc+=2; } examples: stbank r0,@r1 ; before execution: r1 = h'00000108, r0 = h'ffffffff ; after execution: contents of r2 stored r2 = h'ffffffff
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 156 of 484 rej09b0051-0300 6.3.36 stc store control register system control instruction store from control register SH-2A/sh2a-fpu (new) format abstract code cycle t bit stc tbr, rn tbr rn 0000nnnn01001010 1 D description stores data in control register tbr in a destination. operation stctbr(long n) /* stc tbr, rn*/ { r[n]=tbr; pc+=2; } examples: stc tbr,r0 ; before execution: r0 = h'12345678, tbr = h'00000000 ; after execution: r0 = h'00000000
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 157 of 484 rej09b0051-0300 6.4 sh-2e cpu instructions 6.4.1 add add binary arithmetic instruction binary addition format abstract code cycle t bit add rm,rn rm + rn rn 0011nnnnmmmm1100 1? add #imm,rn rn + imm rn 0111nnnniiiiiiii 1? description adds general register rn data to rm data, and stores the result in rn. 8-bit immediate data can be added instead of rm data. since the 8-bit immediate data is sign-extended to 32 bits, this instruction can add and subtract immediate data. operation add(long m,long n) /* add rm,rn */ { r[n]+=r[m]; pc+=2; } addi(long i,long n) /* add #imm,rn */ { if ((i&0x80)==0) r[n]+=(0x000000ff & (long)i); else r[n]+=(0xffffff00 | (long)i); pc+=2; } examples: add r0,r1 ; before execution: r0 = h'7fffffff, r1 = h'00000001 ; after execution: r1 = h'80000000 add #h'01,r2 ; before execution: r2 = h'00000000 ; after execution: r2 = h'00000001 add #h'fe,r3 ; before execution: r3 = h'00000001 ; after execution: r3 = h'ffffffff
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 158 of 484 rej09b0051-0300 6.4.2 addc add with carry arithmetic instruction binary addition with carry format abstract code cycle t bit addc rm,rn rn + rm + t rn, carry t 0011nnnnmmmm1110 1carry description adds rm data and the t bit to general register rn data, and stores the result in rn. the t bit changes according to the result. this instruction can add data that has more than 32 bits. operation addc (long m,long n) /* addc rm,rn */ { unsigned long tmp0,tmp1; tmp1=r[n]+r[m]; tmp0=r[n]; r[n]=tmp1+t; if (tmp0>tmp1) t=1; else t=0; if (tmp1>r[n]) t=1; pc+=2; } examples: clrt ; r0:r1 (64 bits) + r2:r3 (64 bits) = r0:r1 (64 bits) addc r3,r1 ; before execution: t = 0, r1 = h'00000001, r3 = h'ffffffff ; after execution: t = 1, r1 = h'0000000 addc r2,r0 ; before execution: t = 1, r0 = h'00000000, r2 = h'00000000 ; after execution: t = 0, r0 = h'00000001
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 159 of 484 rej09b0051-0300 6.4.3 addv add with (v flag) overflow check arithmetic instruction binary addition with overflow check format abstract code cycle t bit addv rm,rn rn + rm rn, overflow t 0011nnnnmmmm1111 1 overflow description adds general register rn data to rm data, and stores the result in rn. if an overflow occurs, the t bit is set to 1. operation addv(long m,long n) /*addv rm,rn */ { long dest,src,ans; if ((long)r[n]>=0) dest=0; else dest=1; if ((long)r[m]>=0) src=0; else src=1; src+=dest; r[n]+=r[m]; if ((long)r[n]>=0) ans=0; else ans=1; ans+=dest; if (src==0 || src==2) { if (ans==1) t=1; else t=0; } else t=0; pc+=2; }
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 160 of 484 rej09b0051-0300 examples: addv r0,r1 ; before execution: r0 = h'00000001, r1 = h'7ffffffe, t = 0 ; after execution: r1 = h'7fffffff, t = 0 addv r0,r1 ; before execution: r0 = h'00000002, r1 = h'7ffffffe, t = 0 ; after execution: r1 = h'80000000, t = 1
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 161 of 484 rej09b0051-0300 6.4.4 and and logical logical instruction logical and format abstract code cycle t bit and rm,rn rn & rm rn 0010nnnnmmmm1001 1? and #imm,r0 r0 & imm r0 11001001iiiiiiii 1? and.b #imm, @(r0,gbr) (r0 + gbr) & imm (r0 + gbr) 11001101iiiiiiii 3? description logically ands the contents of general registers rn and rm, and stores the result in rn. the contents of general register r0 can be anded with zero-extended 8-bit immediate data. 8-bit memory data pointed to by gbr relative addressing can be anded with 8-bit immediate data. note after and #imm, r0 is executed and the upper 24 bits of r0 are always cleared to 0.
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 162 of 484 rej09b0051-0300 operation and(long m,long n) /* and rm,rn */ { r[n]&=r[m] pc+=2; } andi(long i) /* and #imm,r0 */ { r[0]&=(0x000000ff & (long)i); pc+=2; } andm(long i) /* and.b #imm,@(r0,gbr) */ { long temp; temp=(long)read_byte(gbr+r[0]); temp&=(0x000000ff & (long)i); write_byte(gbr+r[0],temp); pc+=2; } examples: and r0,r1 ; before execution: r0 = h'aaaaaaaa, r1 = h'55555555 ; after execution: r1 = h'00000000 and #h'0f,r0 ; before execution: r0 = h'ffffffff ; after execution: r0 = h'0000000f and.b #h'80,@(r0,gbr) ; before execution: @(r0,gbr) = h'a5 ; after execution: @(r0,gbr) = h'80
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 163 of 484 rej09b0051-0300 6.4.5 bf branch if false branch instruction conditional branch format abstract code cycle t bit bf label when t = 0, disp 2 + pc pc; when t = 1, nop 10001011dddddddd 3/1 ? description reads the t bit, and conditionally branches. if t = 0, it branches to the branch destination address. if t = 1, bf executes the next instruction. the branch destination is an address specified by pc + displacement. however, in this case it is used for address calculation. the pc is the address 4 bytes after this instruction. the 8-bit displacement is sign-extended and doubled. consequently, the relative interval from the branch destination is ?256 to +254 bytes. if the displacement is too short to reach the branch destination, use bf with the bra instruction or the like. note when branching, three cycles; when not branching, one cycle. operation bf(long d) /* bf disp */ { long disp; if ((d&0x80)==0) disp=(0x000000ff & (long)d); else disp=(0xffffff00 | (long)d); if (t==0) pc=pc+(disp<<1); else pc+=2; }
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 164 of 484 rej09b0051-0300 example: clrt ; t is always cleared to 0 bt trget_t ; does not branch, because t = 0 bf trget_f ; branches to trget_f, because t = 0 nop ; nop ; the pc location is used to calculate the branch destination .......... address of the bf instruction trget_f: ; branch destination of the bf instruction
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 165 of 484 rej09b0051-0300 6.4.6 bf/s branch if false with delay slot branch instruction conditional branch with delay delayed branch instruction format abstract code cycle t bit bf/s label when t = 0, disp 2+ pc pc; when t = 1, nop 10001111dddddddd 2/1 ? description reads the t bit and conditionally branches. if t = 0, it branches after executing the next instruction. if t = 1, bf/s executes the next instruction. the branch destination is an address specified by pc + displacement. however, in this case it is used for address calculation. the pc is the address 4 bytes after this instruction. the 8-bit displacement is sign-extended and doubled. consequently, the relative interval from the branch destination is ?256 to +254 bytes. if the displacement is too short to reach the branch destination, use bf with the bra instruction or the like. note since this is a delay branch instruction, the instruction immediately following is executed before the branch. no interrupts and address errors are accepted between this instruction and the next instruction. when the instruction immediately following is a branch instruction, it is recognized as an illegal slot instruction. when branching, this is a two-cycle instruction; when not branching, one cycle.
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 166 of 484 rej09b0051-0300 operation bfs(long d) /* bfs disp */ { long disp; unsigned long temp; temp=pc; if ((d&0x80)==0) disp=(0x000000ff & (long)d); else disp=(0xffffff00 | (long)d); if (t==0) { pc=pc+(disp<<1); delay_slot(temp+2); } else pc+=2; } example: clrt ; t is always 0 bt/s trget_t ; does not branch, because t = 0 nop ; bf/s trget_f ; branches to trget_f, because t = 0 add r0,r1 ; executed before branch. nop ; the pc location is used to calculate the branch destination .......... address of the bf/s instruction trget_f: ; branch destination of the bf/s instruction note: when a delayed branch instruction is used, the branching operation takes place after the slot instruction is executed, but the execution of instructions (register update, etc.) takes place in the sequence delayed branch instruction delayed slot instruction. for example, even if a delayed slot instruction is used to change the register where the branch destination address is stored, the register content previous to the change will be used as the branch destination address.
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 167 of 484 rej09b0051-0300 6.4.7 bra branch branch instruction unconditional branch delayed branch instruction format abstract code cycle t bit bra label disp 2 + pc pc 1010dddddddddddd 2? description branches unconditionally after executing the instruction following this bra instruction. the branch destination is an address specified by pc + displacement. however, in this case it is used for address calculation. the pc is the address 4 bytes after this instruction. the 12-bit displacement is sign-extended and doubled. consequently, the relative interval from the branch destination is ?4096 to +4094 bytes. if the displacement is too short to reach the branch destination, this instruction must be changed to the jmp instruction. here, a mov instruction must be used to transfer the destination address to a register. note since this is a delayed branch instruction, the instruction after bra is executed before branching. no interrupts and address errors are accepted between this instruction and the next instruction. if the next instruction is a branch instruction, it is acknowledged as an illegal slot instruction. operation bra(long d) /* bra disp */ { unsigned long temp; long disp; if ((d&0x800)==0) disp=(0x00000fff & (long) d); else disp=(0xfffff000 | (long) d); temp=pc; pc=pc+(disp<<1); delay_slot(temp+2); }
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 168 of 484 rej09b0051-0300 example: bra trget ; branches to trget add r0,r1 ; executes add before branching nop ; the pc location is used to calculate the branch destination .......... address of the bra instruction trget: ; branch destination of the bra instruction note: when a delayed branch instruction is used, the branching operation takes place after the slot instruction is executed, but the execution of instructions (register update, etc.) takes place in the sequence delayed branch instruction delayed slot instruction. for example, even if a delayed slot instruction is used to change the register where the branch destination address is stored, the register content previous to the change will be used as the branch destination address.
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 169 of 484 rej09b0051-0300 6.4.8 braf branch far branch instruction unconditional branch delayed branch instruction format abstract code cycle t bit braf rm rm + pc pc 0000mmmm00100011 2? description branches unconditionally. the branch destination is pc + the 32-bit contents of the general register rm. however, in this case it is used for address calculation. the pc is the address 4 bytes after this instruction. note since this is a delayed branch instruction, the instruction after braf is executed before branching. no interrupts and address errors are accepted between this instruction and the next instruction. if the next instruction is a branch instruction, it is acknowledged as an illegal slot instruction. operation braf(long m) /* braf rm */ { unsigned long temp; temp=pc; pc=pc+r[m]; delay_slot(temp+2); }
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 170 of 484 rej09b0051-0300 example: mov.l #(target-bsrf_pc),r0 ; sets displacement. bra trget ; branches to target add r0,r1 ; executes add before branching braf_pc: ; the pc location is used to calculate the branch destination address of the braf instruction nop .................... target: ; branch destination of the braf instruction note: when a delayed branch instruction is used, the branching operation takes place after the slot instruction is executed, but the execution of instructions (register update, etc.) takes place in the sequence delayed branch instruction delayed slot instruction. for example, even if a delayed slot instruction is used to change the register where the branch destination address is stored, the register content previous to the change will be used as the branch destination address.
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 171 of 484 rej09b0051-0300 6.4.9 bsr branch to subroutine branch instruction branch to subroutine procedure delayed branch instruction format abstract code cycle t bit bsr label pc pr, disp 2+ pc pc 1011dddddddddddd 2? description branches to the subroutine procedure at a specified address. the pc value is stored in the pr, and the program branches to an address specified by pc + displacement. however, in this case it is used for address calculation. the pc is the address 4 bytes after this instruction. the 12-bit displacement is sign-extended and doubled. consequently, the relative interval from the branch destination is ?4096 to +4094 bytes. if the displacement is too short to reach the branch destination, the jsr instruction must be used instead. with jsr, the destination address must be transferred to a register by using the mov instruction. this bsr instruction and the rts instruction are used together for a subroutine procedure call. note since this is a delayed branch instruction, the instruction after bsr is executed before branching. no interrupts and address errors are accepted between this instruction and the next instruction. if the next instruction is a branch instruction, it is acknowledged as an illegal slot instruction. operation bsr(long d) /* bsr disp */ { long disp; if ((d&0x800)==0) disp=(0x00000fff & (long) d); else disp=(0xfffff000 | (long) d); pr=pc+is_32bit_inst(pr+2); pc=pc+(disp<<1); delay_slot(pr+2); }
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 172 of 484 rej09b0051-0300 example: bsr trget ; branches to trget mov r3,r4 ; executes the mov instruction before branching add r0,r1 ; the pc location is used to calculate the branch destination address of the bsr instruction (return address for when the subroutine procedure is completed (pr data)) ....... ....... trget: ; procedure entrance mov r2,r3 ; rts ; returns to the above add instruction mov #1,r0 ; executes mov before branching note: when a delayed branch instruction is used, the branching operation takes place after the slot instruction is executed, but the execution of instructions (register update, etc.) takes place in the sequence delayed branch instruction delayed slot instruction. for example, even if a delayed slot instruction is used to change the register where the branch destination address is stored, the register content previous to the change will be used as the branch destination address.
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 173 of 484 rej09b0051-0300 6.4.10 bsrf branch to subroutine far branch instruction branch to subroutine procedure delayed branch instruction format abstract code cycle t bit bsrf rm pc pr, rm + pc pc 0000mmmm00000011 2? description branches to the subroutine procedure at a specified address after executing the instruction following this bsrf instruction. the pc value is stored in the pr. the branch destination is pc + the 32-bit contents of the general register rm. however, in this case it is used for address calculation. the pc is the address 4 bytes after this instruction. used as a subroutine procedure call in combination with rts. note since this is a delayed branch instruction, the instruction after bsr is executed before branching. no interrupts and address errors are accepted between this instruction and the next instruction. if the next instruction is a branch instruction, it is acknowledged as an illegal slot instruction. operation bsrf(long m) /* bsrf rm */ { pr=pc pc=pc+r[m]; delay_slot(pr+2); }
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 174 of 484 rej09b0051-0300 example: mov.l #(target-bsrf_pc),r0 ; sets displacement. brsf r0 ; branches to target mov r3,r4 ; executes the mov instruction before branching bsrf_pc: ; the pc location is used to calculate the branch destination with bsrf. add r0,r1 ..... ..... target: ; ? procedure entrance mov r2,r3 ; rts ; returns to the above add instruction mov #1,r0 ; executes mov before branching note: when a delayed branch instruction is used, the branching operation takes place after the slot instruction is executed, but the execution of instructions (register update, etc.) takes place in the sequence delayed branch instruction delayed slot instruction. for example, even if a delayed slot instruction is used to change the register where the branch destination address is stored, the register content previous to the change will be used as the branch destination address.
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 175 of 484 rej09b0051-0300 6.4.11 bt branch if true branch instruction conditional branch format abstract code cycle t bit bt label when t = 1, disp 2 + pc pc; when t = 0, nop 10001001dddddddd 3/1 ? description reads the t bit, and conditionally branches. if t = 1, bt branches. if t = 0, bt executes the next instruction. the branch destination is an address specified by pc + displacement. however, in this case it is used for address calculation. the pc is the address 4 bytes after this instruction. the 8- bit displacement is sign-extended and doubled. consequently, the relative interval from the branch destination is ?256 to +254 bytes. if the displacement is too short to reach the branch destination, use bt with the bra instruction or the like. note when branching, requires three cycles; when not branching, one cycle. operation bt(long d) /* bt disp */ { long disp; if ((d&0x80)==0) disp=(0x000000ff & (long)d); else disp=(0xffffff00 | (long)d); if (t==1) pc=pc+(disp<<1); else pc+=2; }
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 176 of 484 rej09b0051-0300 example: sett ; t is always 1 bf trget_f ; does not branch, because t = 1 bt trget_t ; branches to trget_t, because t = 1 nop ; nop ; the pc location is used to calculate the branch destination .......... address of the bt instruction trget_t: ; branch destination of the bt instruction
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 177 of 484 rej09b0051-0300 6.4.12 bt/s branch if true with delay slot branch instruction conditional branch with delay delayed branch instruction format abstract code cycle t bit bt/s label when t = 1, disp 2 + pc pc; when t = 0, nop 10001101dddddddd 2/1 ? description reads the t bit and conditionally branches. if t = 1, bt/s branches after the following instruction executes. if t = 0, bt/s executes the next instruction. the branch destination is an address specified by pc + displacement. however, in this case it is used for address calculation. the pc is the address 4 bytes after this instruction. the 8-bit displacement is sign-extended and doubled. consequently, the relative interval from the branch destination is ?256 to +254 bytes. if the displacement is too short to reach the branch destination, use bt/s with the bra instruction or the like. note since this is a delay branch instruction, the instruction immediately following is executed before the branch. no interrupts and address errors are accepted between this instruction and the next instruction. when the immediately following instruction is a branch instruction, it is recognized as an illegal slot instruction. when branching, requires two cycles; when not branching, one cycle.
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 178 of 484 rej09b0051-0300 operation bts(long d) /* bts disp */ { long disp; unsigned long temp; temp=pc; if ((d&0x80)==0) disp=(0x000000ff & (long)d); else disp=(0xffffff00 | (long)d); if (t==1) { pc=pc+(disp<<1); delay_slot(temp+2); } else pc+=2; } example: sett ; t is always 1 bf/s target_f ; does not branch, because t = 1 nop ; bt/s target_t ; branches to target, because t = 1 add r0,r1 ; executes before branching. nop ; the pc location is used to calculate the branch destination .......... address of the bt/s instruction target_t: ; branch destination of the bt/s instruction note: when a delayed branch instruction is used, the branching operation takes place after the slot instruction is executed, but the execution of instructions (register update, etc.) takes place in the sequence delayed branch instruction delayed slot instruction. for example, even if a delayed slot instruction is used to change the register where the branch destination address is stored, the register content previous to the change will be used as the branch destination address.
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 179 of 484 rej09b0051-0300 6.4.13 clrmac clear mac register system control instruction mac register clear format abstract code cycle t bit clrmac 0 mach, macl 0000000000101000 1? description clear the mach and macl register. operation clrmac() /* clrmac */ { mach=0; macl=0; pc+=2; } example: clrmac ; clears and initializes the mac register mac.w @r0+,@r1+ ; multiply and accumulate operation mac.w @r0+,@r1+ ;
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 180 of 484 rej09b0051-0300 6.4.14 clrt clear t bit system control instruction t bit clear format abstract code cycle t bit clrt 0 t 0000000000001000 10 description clears the t bit. operation clrt() /* clrt */ { t=0; pc+=2; } example: clrt ; before execution: t = 1 ; after execution: t = 0
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 181 of 484 rej09b0051-0300 6.4.15 cmp/cond compare conditionally arithmetic instruction compare format abstract code cycle t bit cmp/eq rm,rn when rn = rm, 1 t 0011nnnnmmmm0000 1 comparison result cmp/ge rm,rn when signed and rn rm, 1 t 0011nnnnmmmm0011 1 comparison result cmp/gt rm,rn when signed and rn > rm, 1 t 0011nnnnmmmm0111 1 comparison result cmp/hi rm,rn when unsigned and rn > rm, 1 t 0011nnnnmmmm0110 1 comparison result cmp/hs rm,rn when unsigned and rn rm, 1 t 0011nnnnmmmm0010 1 comparison result cmp/pl rn when rn > 0, 1 t 0100nnnn00010101 1 comparison result cmp/pz rn when rn 0, 1 t 0100nnnn00010001 1 comparison result cmp/str rm,rn when a byte in rn equals a byte in rm, 1 t 0010nnnnmmmm1100 1 comparison result cmp/eq #imm,r0 when r0 = imm, 1 t 10001000iiiiiiii 1 comparison result description compares general register rn data with rm data, and sets the t bit to 1 if a specified condition (cond) is satisfied. the t bit is cleared to 0 if the condition is not satisfied. the rn data does not change. the following eight conditions can be specified. conditions pz and pl are the results of comparisons between rn and 0. sign-extended 8-bit immediate data can also be compared with r0 by using condition eq. here, r0 data does not change. table 6.1 shows the mnemonics for the conditions.
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 182 of 484 rej09b0051-0300 table 6.1 cmp mnemonics mnemonics condition cmp/eq rm,rn if rn = rm, t = 1 cmp/ge rm,rn if rn rm with signed data, t = 1 cmp/gt rm,rn if rn > rm with signed data, t = 1 cmp/hi rm,rn if rn > rm with unsigned data, t = 1 cmp/hs rm,rn if rn rm with unsigned data, t = 1 cmp/pl rn if rn > 0, t = 1 cmp/pz rn if rn 0, t = 1 cmp/str rm,rn if a byte in rn equals a byte in rm, t = 1 cmp/eq #imm,r0 if r0 = imm, t = 1 operation cmpeq(long m,long n) /* cmp_eq rm,rn */ { if (r[n]==r[m]) t=1; else t=0; pc+=2; } cmpge(long m,long n) /* cmp_ge rm,rn */ { if ((long)r[n]>=(long)r[m]) t=1; else t=0; pc+=2; } cmpgt(long m,long n) /* cmp_gt rm,rn */ { if ((long)r[n]>(long)r[m]) t=1; else t=0; pc+=2; } cmphi(long m,long n) /* cmp_hi rm,rn */ { if ((unsigned long)r[n]>(unsigned long)r[m]) t=1;
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 183 of 484 rej09b0051-0300 else t=0; pc+=2; } cmphs(long m,long n) /* cmp_hs rm,rn */ { if ((unsigned long)r[n]>=(unsigned long)r[m]) t=1; else t=0; pc+=2; } cmppl(long n) /* cmp_pl rn */ { if ((long)r[n]>0) t=1; else t=0; pc+=2; } cmppz(long n) /* cmp_pz rn */ { if ((long)r[n]>=0) t=1; else t=0; pc+=2; } cmpstr(long m,long n) /* cmp_str rm,rn */ { unsigned long temp; long hh,hl,lh,ll; temp=r[n]^r[m]; hh=(temp>>24)&0x000000ff; hl=(temp>>16)&0x000000ff; lh=(temp>>8)&0x000000ff; ll=temp&0x000000ff; hh=hh&&hl&&lh&≪ if (hh==0) t=1; else t=0; pc+=2;
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 184 of 484 rej09b0051-0300 } cmpim(long i) /* cmp_eq #imm,r0 */ { long imm; if ((i&0x80)==0) imm=(0x000000ff & (long i)); else imm=(0xffffff00 | (long i)); if (r[0]==imm) t=1; else t=0; pc+=2; } example: cmp/ge r0,r1 ; r0 = h'7fffffff, r1 = h'80000000 bt trget_t ; does not branch because t = 0 cmp/hs r0,r1 ; r0 = h'7fffffff, r1 = h'80000000 bt trget_t ; branches because t = 1 cmp/str r2,r3 ; r2 = ?abcd?, r3 = ?xycz? bt trget_t ; branches because t = 1
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 185 of 484 rej09b0051-0300 6.4.16 div0s divide (step 0) as signed arithmetic instruction initialization for signed division format abstract code cycle t bit div0s rm,rn msb of rn q, msb of rm m, m^q t 0010nnnnmmmm0111 1 calculation result description div0s is an initialization instruction for signed division. it finds the quotient by repeatedly dividing in combination with the div1 or another instruction that divides for each bit after this instruction. see the description given with div1 for more information. operation div0s(long m,long n) /* div0s rm,rn */ { if ((r[n]&0x80000000)==0) q=0; else q=1; if ((r[m]&0x80000000)==0) m=0; else m=1; t=!(m==q); pc+=2; } example: see div1.
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 186 of 484 rej09b0051-0300 6.4.17 div0u divide (step 0) as unsigned arithmetic instruction initialization for unsigned division format abstract code cycle t bit div0u 0 m/q/t 0000000000011001 10 description div0u is an initialization instruction for unsigned division. it finds the quotient by repeatedly dividing in combination with the div1 or another instruction that divides for each bit after this instruction. see the description given with div1 for more information. operation div0u() /* div0u */ { m=q=t=0; pc+=2; } example: see div1.
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 187 of 484 rej09b0051-0300 6.4.18 div1 divide 1 step arithmetic instruction division format abstract code cycle t bit div1 rm,rn 1 step division (rn rm) 0011nnnnmmmm0100 1 calculation result description uses single-step division to divide one bit of the 32-bit data in general register rn (dividend) by rm data (divisor). it finds a quotient through repetition either independently or used in combination with other instructions. during this repetition, do not rewrite the specified register or the m, q, and t bits. in one-step division, the dividend is shifted one bit left, the divisor is subtracted and the quotient bit reflected in the q bit according to the status (positive or negative). to find the remainder in a division, first find the quotient using a div1 instruction, then find the remainder as follows: (dividend) ? (divisor) (quotient) = (remainder) zero division, overflow detection, and remainder operation are not supported. check for zero division and overflow division before dividing. find the remainder by first finding the sum of the divisor and the quotient obtained and then subtracting it from the dividend. that is, first initialize with div0s or div0u. repeat div1 for each bit of the divisor to obtain the quotient. when the quotient requires 17 or more bits, place rotcl before div1. for the division sequence, see the following examples.
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 188 of 484 rej09b0051-0300 operation div1(long m,long n) /* div1 rm,rn */ { unsigned long tmp0; unsigned char old_q,tmp1; old_q=q; q=(unsigned char)((0x80000000 & r[n])!=0); r[n]<<=1; r[n]|=(unsigned long)t; switch(old_q){ case 0:switch(m){ case 0:tmp0=r[n]; r[n]-=r[m]; tmp1=(r[n]>tmp0); switch(q){ case 0:q=tmp1; break; case 1:q=(unsigned char)(tmp1==0); break; } break; case 1:tmp0=r[n]; r[n]+=r[m]; tmp1=(r[n] section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 189 of 484 rej09b0051-0300 case 1:switch(m){ case 0:tmp0=r[n]; r[n]+=r[m]; tmp1=(r[n]tmp0); switch(q){ case 0:q=(unsigned char)(tmp1==0); break; case 1:q=tmp1; break; } break; } break; } t=(q==m); pc+=2; }
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 190 of 484 rej09b0051-0300 example 1: ; r1 (32 bits) / r0 (16 bits) = r1 (16 bits):unsigned shll16 r0 ; upper 16 bits = divisor, lower 16 bits = 0 tst r0,r0 ; zero division check bt zero_div ; cmp/hs r0,r1 ; overflow check bt over_div ; div0u ; flag initialization .arepeat 16 ; div1 r0,r1 ; repeat 16 times .aendr ; rotcl r1 ; extu.w r1,r1 ; r1 = quotient example 2: ; r1:r2 (64 bits)/r0 (32 bits) = r2 (32 bits):unsigned tst r0,r0 ; zero division check bt zero_div ; cmp/hs ;r0,r1 ; overflow check bt over_div ; div0u ; flag initialization .arepeat 32 ; rotcl r2 ; repeat 32 times div1 r0,r1 ; .aendr ; rotcl r2 ; r2 = quotient
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 191 of 484 rej09b0051-0300 example 3: ; r1 (16 bits)/r0 (16 bits) = r1 (16 bits):signed shll16 r0 ; upper 16 bits = divisor, lower 16 bits = 0 exts.w r1,r1 ; sign-extends the dividend to 32 bits xor r2,r2 ; r2 = 0 mov r1,r3 ; rotcl r3 ; subc r2,r1 ; decrements if the dividend is negative div0s r0,r1 ; flag initialization .arepeat 16 ; div1 r0,r1 ; repeat 16 times .aendr exts.w r1,r1 ; rotcl r1 ; r1 = quotient (one?s complement) addc r2,r1 ; increments and takes the two?s complement if the msb of the quotient is 1 exts.w r1,r1 ; r1 = quotient (two?s complement) example 4: ; r2 (32 bits) / r0 (32 bits) = r2 (32 bits):signed mov r2,r3 ; rotcl r3 ; subc r1,r1 ; sign-extends the dividend to 64 bits (r1:r2) xor r3,r3 ; r3 = 0 subc r3,r2 ; decrements and takes the one?s complement if the dividend is negative div0s r0,r1 ; flag initialization .arepeat 32 ; rotcl r2 ; repeat 32 times div1 r0,r1 ; .aendr ; rotcl r2 ; r2 = quotient (one?s complement) addc r3,r2 ; increments and takes the two?s complement if the msb of the quotient is 1. r2 = quotient (two?s complement )
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 192 of 484 rej09b0051-0300 6.4.19 dmuls.l double-length multiply as signed arithmetic instruction signed double-length multiplication format abstract code cycle t bit dmuls.l rm, rn with sign, rn rm mach, macl 0011nnnnmmmm1101 4? description performs 32-bit multiplication of the contents of general registers rn and rm, and stores the 64- bit results in the macl and mach register. the operation is a signed arithmetic operation. operation dmuls(long m,long n) /* dmuls.l rm,rn */ { unsigned long rnl,rnh,rml,rmh,res0,res1,res2; unsigned long temp0,temp1,temp2,temp3; long tempm,tempn,fnlml; tempn=(long)r[n]; tempm=(long)r[m]; if (tempn<0) tempn=0-tempn; if (tempm<0) tempm=0-tempm; if ((long)(r[n]^r[m])<0) fnlml=-1; else fnlml=0; temp1=(unsigned long)tempn; temp2=(unsigned long)tempm; rnl=temp1&0x0000ffff; rnh=(temp1>>16)&0x0000ffff; rml=temp2&0x0000ffff; rmh=(temp2>>16)&0x0000ffff;
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 193 of 484 rej09b0051-0300 temp0=rml*rnl; temp1=rmh*rnl; temp2=rml*rnh; temp3=rmh*rnh; res2=0 res1=temp1+temp2; if (res1>16)&0x0000ffff)+temp3; if (fnlml<0) { res2=~res2; if (res0==0) res2++; else res0=(~res0)+1; } mach=res2; macl=res0; pc+=2; } example: dmuls.l r0,r1 ; before execution: r0 = h'fffffffe, r1 = h'00005555 ; after execution: mach = h'ffffffff, macl = h'ffff5556 sts mach,r0 ; operation result (top) sts macl,r0 ; operation result (bottom)
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 194 of 484 rej09b0051-0300 6.4.20 dmulu.l double-length multiply as unsigned arithmetic instruction unsigned double-length multiplication format abstract code cycle t bit dmulu.l rm, rn without sign, rn rm mach, macl 0011nnnnmmmm0101 2? description performs 32-bit multiplication of the contents of general registers rn and rm, and stores the 64- bit results in the macl and mach register. the operation is an unsigned arithmetic operation. operation dmulu(long m,long n) /* dmulu.l rm,rn */ { unsigned long rnl,rnh,rml,rmh,res0,res1,res2; unsigned long temp0,temp1,temp2,temp3; rnl=r[n]&0x0000ffff; rnh=(r[n]>>16)&0x0000ffff; rml=r[m]&0x0000ffff; rmh=(r[m]>>16)&0x0000ffff; temp0=rml*rnl; temp1=rmh*rnl; temp2=rml*rnh; temp3=rmh*rnh; res2=0 res1=temp1+temp2; if (res1 section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 195 of 484 rej09b0051-0300 res0=temp0+temp1; if (res0>16)&0x0000ffff)+temp3; mach=res2; macl=res0; pc+=2; } example: dmulu.l r0,r1 ; before execution: r0 = h'fffffffe, r1 = h'00005555 ; after execution: mach = h'ffffffff, macl = h'ffff5556 sts mach,r0 ; operation result (top) sts macl,r0 ; operation result (bottom)
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 196 of 484 rej09b0051-0300 6.4.21 dt decrement and test arithmetic instruction decrement and test format abstract code cycle t bit dt rn rn ? 1 rn; when rn is 0, 1 t, when rn is nonzero, 0 t 0100nnnn00010000 1 comparison result description the contents of general register rn are decremented by 1 and the result compared to 0 (zero). when the result is 0, the t bit is set to 1. when the result is not zero, the t bit is set to 0. operation dt(long n) /* dt rn */ { r[n]--; if (r[n]==0) t=1; else t=0; pc+=2; } example: mov #4,r5 ; sets the number of loops. loop: add r0,r1 ; dt r5 ; decrements the r5 value and checks whether it has become 0. bf loop ; branches to loop is t=0. (in this example, loops 4 times.)
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 197 of 484 rej09b0051-0300 6.4.22 exts extend as signed arithmetic instruction sign extension format abstract code cycle t bit exts.b rm, rn sign-extend rm from byte rn 0110nnnnmmmm1110 1? exts.w rm, rn sign-extend rm from word rn 0110nnnnmmmm1111 1? description sign-extends general register rm data, and stores the result in rn. if byte length is specified, the bit 7 value of rm is copied into bits 8 to 31 of rn. if word length is specified, the bit 15 value of rm is copied into bits 16 to 31 of rn. operation extsb(long m,long n) /* exts.b rm,rn */ { r[n]=r[m]; if ((r[m]&0x00000080)==0) r[n]&=0x000000ff; else r[n]|=0xffffff00; pc+=2; } extsw(long m,long n) /* exts.w rm,rn */ { r[n]=r[m]; if ((r[m]&0x00008000)==0) r[n]&=0x0000ffff; else r[n]|=0xffff0000; pc+=2; } examples: exts.b r0,r1 ; before execution: r0 = h'00000080 ; after execution: r1 = h'ffffff80 exts.w r0,r1 ; before execution: r0 = h'00008000 ; after execution: r1 = h'ffff8000
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 198 of 484 rej09b0051-0300 6.4.23 extu extend as unsigned arithmetic instruction zero extension format abstract code cycle t bit extu.b rm, rn zero-extend rm from byte rn 0110nnnnmmmm1100 1? extu.w rm, rn zero-extend rm from word rn 0110nnnnmmmm1101 1? description zero-extends general register rm data, and stores the result in rn. if byte length is specified, 0s are written in bits 8 to 31 of rn. if word length is specified, 0s are written in bits 16 to 31 of rn. operation extub(long m,long n) /* extu.b rm,rn */ { r[n]=r[m]; r[n]&=0x000000ff; pc+=2; } extuw(long m,long n) /* extu.w rm,rn */ { r[n]=r[m]; r[n]&=0x0000ffff; pc+=2; } examples: extu.b r0,r1 ; before execution: r0 = h'ffffff80 ; after execution: r1 = h'00000080 extu.w r0,r1 ; before execution: r0 = h'ffff8000 ; after execution: r1 = h'00008000
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 199 of 484 rej09b0051-0300 6.4.24 jmp jump branch instruction unconditional branch delayed branch instruction format abstract code cycle t bit jmp @rm rm pc 0100mmmm00101011 2? description branches unconditionally to the address specified by register indirect addressing. the branch destination is an address specified by the 32-bit data in general register rm. note since this is a delayed branch instruction, the instruction after jmp is executed before branching. no interrupts or address errors are accepted between this instruction and the next instruction. if the next instruction is a branch instruction, it is acknowledged as an illegal slot instruction. operation jmp(long m) /* jmp @rm */ { unsigned long temp; temp=pc; pc=r[m]+4; delay_slot(temp+2); }
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 200 of 484 rej09b0051-0300 example: mov.l jmp_table,r0 ; address of r0 = trget jmp @r0 ; branches to trget mov r0,r1 ; executes mov before branching .align 4 jmp_table: .data.l trget ; jump table ................. trget: add #1,r1 ; branch destination note: when a delayed branch instruction is used, the branching operation takes place after the slot instruction is executed, but the execution of instructions (register update, etc.) takes place in the sequence delayed branch instruction delayed slot instruction. for example, even if a delayed slot instruction is used to change the register where the branch destination address is stored, the register content previous to the change will be used as the branch destination address.
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 201 of 484 rej09b0051-0300 6.4.25 jsr jump to subroutine branch instruction branch to subroutine procedure delayed branch instruction format abstract code cycle t bit jsr @rm pc pr, rm pc 0100mmmm00001011 2? description branches to the subroutine procedure at the address specified by register indirect addressing. the pc value is stored in the pr. the jump destination is an address specified by the 32-bit data in general register rm. the stored/saved pc is the address four bytes after this instruction. the jsr instruction and rts instruction are used together for subroutine procedure calls. note since this is a delayed branch instruction, the instruction after jsr is executed before branching. no interrupts and address errors are accepted between this instruction and the next instruction. if the next instruction is a branch instruction, it is acknowledged as an illegal slot instruction. operation jsr(long m) /* jsr @rm */ { pr=pc; pc=r[m]+4; delay_slot(pr+2); }
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 202 of 484 rej09b0051-0300 example: mov.l jsr_table,r0 ; address of r0 = trget jsr @r0 ; branches to trget xor r1,r1 ; executes xor before branching add r0,r1 ; return address for when the subroutine procedure is completed (pr data) ........... .align 4 jsr_table: .data.l trget ; jump table trget: nop ; procedure entrance mov r2,r3 ; rts ; returns to the above add instruction mov #70,r1 ; executes mov before rts note: when a delayed branch instruction is used, the branching operation takes place after the slot instruction is executed, but the execution of instructions (register update, etc.) takes place in the sequence delayed branch instruction delayed slot instruction. for example, even if a delayed slot instruction is used to change the register where the branch destination address is stored, the register content previous to the change will be used as the branch destination address.
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 203 of 484 rej09b0051-0300 6.4.26 ldc load to control register system control instruction load to control register format abstract code cycle t bit ldc rm,sr rm sr 0100mmmm00001110 3lsb ldc rm,gbr rm gbr 0100mmmm00011110 1? ldc rm,vbr rm vbr 0100mmmm00101110 1? ldc.l @rm+,sr (rm) sr, rm + 4 rm 0100mmmm00000111 5lsb ldc.l @rm+,gbr (rm) gbr, rm + 4 rm 0100mmmm00010111 1? ldc.l @rm+,vbr (rm) vbr, rm + 4 rm 0100mmmm00100111 1? description store the source operand into control register sr, gbr, or vbr. operation ldcsr(long m) /* ldc rm,sr */ { sr=r[m]&0x000063f3; pc+=2; } ldcgbr(long m) /* ldc rm,gbr */ { gbr=r[m]; pc+=2; } ldcvbr(long m) /* ldc rm,vbr */ { vbr=r[m]; pc+=2; } ldcmsr(long m) /* ldc.l @rm+,sr */ { sr=read_long(r[m])&0x000063f3;
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 204 of 484 rej09b0051-0300 r[m]+=4; pc+=2; } ldcmgbr(long m) /* ldc.l @rm+,gbr */ { gbr=read_long(r[m]); r[m]+=4; pc+=2; } ldcmvbr(long m) /* ldc.l @rm+,vbr */ { vbr=read_long(r[m]); r[m]+=4; pc+=2; } examples: ldc r0,sr ; before execution: r0 = h'ffffffff, sr = h'00000000 ; after execution: sr = h'000063f3 ldc.l @r15+,gbr ; before execution: r15 = h'10000000 ; after execution: r15 = h'10000004, gbr = @h'10000000
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 205 of 484 rej09b0051-0300 6.4.27 lds load to system register system control instruction load to system register format abstract code cycle t bit lds rm,mach rm mach 0100mmmm00001010 1? lds rm,macl rm macl 0100mmmm00011010 1? lds rm,pr rm pr 0100mmmm00101010 1? lds.l @rm+, mach (rm) mach, rm + 4 rm 0100mmmm00000110 1? lds.l @rm+, macl (rm) macl, rm + 4 rm 0100mmmm00010110 1? lds.l @rm+,pr (rm) pr, rm + 4 rm 0100mmmm00100110 1? description store the source operand into the system register mach, macl, or pr. operation ldsmach(long m) /* lds rm,mach */ { mach=r[m]; pc+=2; } ldsmacl(long m) /* lds rm,macl */ { macl=r[m]; pc+=2; } ldspr(long m) /* lds rm,pr */ { pr=r[m]; pc+=2; } ldsmmach(long m) /* lds.l @rm+,mach */ { mach=read_long(r[m]);
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 206 of 484 rej09b0051-0300 r[m]+=4; pc+=2; } ldsmmacl(long m) /* lds.l @rm+,macl */ { macl=read_long(r[m]); r[m]+=4; pc+=2; } ldsmpr(long m) /* lds.l @rm+,pr */ { pr=read_long(r[m]); r[m]+=4; pc+=2; } examples: lds r0,pr ; before execution: r0 = h'12345678, pr = h'00000000 ; after execution: pr = h'12345678 lds.l @r15+,macl ; before execution: r15 = h'10000000 ; after execution: r15 = h'10000004, macl = @h'10000000
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 207 of 484 rej09b0051-0300 6.4.28 mac.l multiply and accumulate long arithmetic instruction double-precision multiply-and-accumulate operation format abstract code cycle t bit mac.l @rm+, @rn+ signed operation, (rn) (rm) + mac mac 0000nnnnmmmm1111 4? description does signed multiplication of 32-bit operands obtained using the contents of general registers rm and rn as addresses. the 64-bit result is added to contents of the mac register, and the final result is stored in the mac register. every time an operand is read, they increment rm and rn by four. when the s bit is cleared to 0, the 64-bit result is stored in the coupled mach and macl registers. when bit s is set to 1, addition to the mac register is a saturation operation of 48 bits starting from the lsb. for the saturation operation, only the lower 48 bits of the macl register are enabled and the result is limited to a range of h'ffff800000000000 (minimum) and h'00007fffffffffff (maximum). operation macl(long m,long n) /* mac.l @rm+,@rn+*/ { unsigned long rnl,rnh,rml,rmh,res0,res1,res2; unsigned long temp0,templ,temp2,temp3; long tempm,tempn,fnlml; tempn=(long)read_long(r[n]); r[n]+=4; tempm=(long)read_long(r[m]); r[m]+=4; if ((long)(tempn^tempm)<0) fnlml=-1; else fnlml=0;
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 208 of 484 rej09b0051-0300 if (tempn<0) tempn=0-tempn; if (tempm<0) tempm=0-tempm; temp1=(unsigned long)tempn; temp2=(unsigned long)tempm; rnl=temp1&0x0000ffff; rnh=(temp1>>16)&0x0000ffff; rml=temp2&0x0000ffff; rmh=(temp2>>16)&0x0000ffff; temp0=rml*rnl; temp1=rmh*rnl; temp2=rml*rnh; temp3=rmh*rnh; res2=0 res1=temp1+temp2; if (res1>16)&0x0000ffff)+temp3; if(fnlml<0){ res2=~res2; if (res0==0) res2++; else res0=(~res0)+1; } if(s==1){ res0=macl+res0; if (macl>res0) res2++;
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 209 of 484 rej09b0051-0300 if (mach&0x00008000); else res2+=mach|0xffff0000; res2+=mach&0x00007fff; if(((long)res2<0)&&(res2<0xffff8000)){ res2=0xffff8000; res0=0x00000000; } if(((long)res2>0)&&(res2>0x00007fff)){ res2=0x00007fff; res0=0xffffffff; }; mach=(res2&0x0000ffff)|(mach&0xffff0000) macl=res0; } else { res0=macl+res0; if (macl>res0) res2++; res2+=mach mach=res2; macl=res0; } pc+=2; }
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 210 of 484 rej09b0051-0300 example: mova tblm,r0 ; table address mov r0,r1 ; mova tbln,r0 ; table address clrmac ; mac register initialization mac.l @r0+,@r1+ ; mac.l @r0+,@r1+ ; sts macl,r0 ; store result into r0 ............... .align 2 ; tblm .data.l h'1234abcd ; .data.l h'5678ef01 ; tbln .data.l h'0123abcd ; .data.l h'4567def0 ;
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 211 of 484 rej09b0051-0300 6.4.29 mac.w multiply and accumulate word arithmetic instruction single-precision multiply-and-accumulate operation format abstract code cycle t bit mac.w @rm+, @rn+ with sign, (rn) (rm) + mac mac 0100nnnnmmmm1111 3? mac @rm+, @rn+ description does signed multiplication of 16-bit operands obtained using the contents of general registers rm and rn as addresses. the 32-bit result is added to contents of the mac register, and the final result is stored in the mac register. rm and rn data are incremented by 2 after the operation. when the s bit is cleared to 0, the operation is 16 16 + 64 64-bit multiply and accumulate and the 64-bit result is stored in the coupled mach and macl registers. when the s bit is set to 1, the operation is 16 16 + 32 32-bit multiply and accumulate and addition to the mac register is a saturation operation. for the saturation operation, only the macl register is enabled and the result is limited to a range of h'80000000 (minimum) and h'7fffffff (maximum). if an overflow occurs, the mach register is set to h'00000001. the result is stored in the macl register. the result is limited to a value between h'80000000 (minimum) for overflows in the negative direction and h'7fffffff (maximum) for overflows in the positive direction. operation macw(long m,long n) /* mac.w @rm+,@rn+*/ { long tempm,tempn,dest,src,ans; unsigned long templ; tempn=(long)read_word(r[n]); r[n]+=2; tempm=(long)read_word(r[m]); r[m]+=2;
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 212 of 484 rej09b0051-0300 templ=macl; tempm=((long)(short)tempn*(long)(short)tempm); if ((long)macl>=0) dest=0; else dest=1; if ((long)tempm>=0 { src=0; tempn=0; } else { src=1; tempn=0xffffffff; } src+=dest; macl+=tempm; if ((long)macl>=0) ans=0; else ans=1; ans+=dest; if (s==1) { if (ans==1) { mach=0x00000001; if (src==0) macl=0x7fffffff; if (src==2) macl=0x80000000; } } else { mach+=tempn; if (templ>macl) mach+=1; } pc+=2; }
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 213 of 484 rej09b0051-0300 example: mova tblm,r0 ; table address mov r0,r1 ; mova tbln,r0 ; table address clrmac ; mac register initialization mac.w @r0+,@r1+ ; mac.w @r0+,@r1+ ; sts macl,r0 ; store result into r0 ............... .align 2 ; tblm .data.w h'1234 ; .data.w h'5678 ; tbln .data.w h'0123 ; .data.w h'4567 ;
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 214 of 484 rej09b0051-0300 6.4.30 mov move data data transfer instruction data transfer format abstract code cycle t bit mov rm,rn rm rn 0110nnnnmmmm0011 1? mov.b rm,@rn rm (rn) 0010nnnnmmmm0000 1? mov.w rm,@rn rm (rn) 0010nnnnmmmm0001 1? mov.l rm,@rn rm (rn) 0010nnnnmmmm0010 1? mov.b @rm,rn (rm) sign extension rn 0110nnnnmmmm0000 1? mov.w @rm,rn (rm) sign extension rn 0110nnnnmmmm0001 1? mov.l @rm,rn (rm) rn 0110nnnnmmmm0010 1? mov.b rm,@?rn rn ? 1 rn, rm (rn) 0010nnnnmmmm0100 1? mov.w rm,@?rn rn ? 2 rn, rm (rn) 0010nnnnmmmm0101 1? mov.l rm,@?rn rn ? 4 rn, rm (rn) 0010nnnnmmmm0110 1? mov.b @rm+,rn (rm) sign extension rn, rm + 1 rm 0110nnnnmmmm0100 1? mov.w @rm+,rn (rm) sign extension rn, rm + 2 rm 0110nnnnmmmm0101 1? mov.l @rm+,rn (rm) rn, rm + 4 rm 0110nnnnmmmm0110 1? mov.b rm,@(r0,rn) rm (r0 + rn) 0000nnnnmmmm0100 1? mov.w rm,@(r0,rn) rm (r0 + rn) 0000nnnnmmmm0101 1? mov.l rm,@(r0,rn) rm (r0 + rn) 0000nnnnmmmm0110 1? mov.b @(r0,rm),rn (r0 + rm) sign extension rn 0000nnnnmmmm1100 1? mov.w @(r0,rm),rn (r0 + rm) sign extension rn 0000nnnnmmmm1101 1? mov.l @(r0,rm),rn (r0 + rm) rn 0000nnnnmmmm1110 1? description transfers the source operand to the destination. when the operand is stored in memory, the transferred data can be a byte, word, or longword. loaded data from memory is stored in a register after it is sign-extended to a longword.
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 215 of 484 rej09b0051-0300 operation mov(long m,long n) /* mov rm,rn */ { r[n]=r[m]; pc+=2; } movbs(long m,long n) /* mov.b rm,@rn */ { write_byte(r[n],r[m]); pc+=2; } movws(long m,long n) /* mov.w rm,@rn */ { write_word(r[n],r[m]); pc+=2; } movls(long m,long n) /* mov.l rm,@rn */ { write_long(r[n],r[m]); pc+=2; } movbl(long m,long n) /* mov.b @rm,rn */ { r[n]=(long)read_byte(r[m]); if ((r[n]&0x80)==0) r[n]&0x000000ff; else r[n]|=0xffffff00; pc+=2; } movwl(long m,long n) /* mov.w @rm,rn */ { r[n]=(long)read_word(r[m]); if ((r[n]&0x8000)==0) r[n]&0x0000ffff; else r[n]|=0xffff0000; pc+=2; }
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 216 of 484 rej09b0051-0300 movll(long m,long n) /* mov.l @rm,rn */ { r[n]=read_long(r[m]); pc+=2; } movbm(long m,long n) /* mov.b rm,@?rn */ { write_byte(r[n]?1,r[m]); r[n]?=1; pc+=2; } movwm(long m,long n) /* mov.w rm,@?rn */ { write_word(r[n]?2,r[m]); r[n]?=2; pc+=2; } movlm(long m,long n) /* mov.l rm,@?rn */ { write_long(r[n]?4,r[m]); r[n]?=4; pc+=2; } movbp(long m,long n) /* mov.b @rm+,rn */ { r[n]=(long)read_byte(r[m]); if ((r[n]&0x80)==0) r[n]&0x000000ff; else r[n]|=0xffffff00; if (n!=m) r[m]+=1; pc+=2; } movwp(long m,long n) /* mov.w @rm+,rn */ { r[n]=(long)read_word(r[m]); if ((r[n]&0x8000)==0) r[n]&0x0000ffff;
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 217 of 484 rej09b0051-0300 else r[n]|=0xffff0000; if (n!=m) r[m]+=2; pc+=2; } movlp(long m,long n) /* mov.l @rm+,rn */ { r[n]=read_long(r[m]); if (n!=m) r[m]+=4; pc+=2; } movbs0(long m,long n) /* mov.b rm,@(r0,rn) */ { write_byte(r[n]+r[0],r[m]); pc+=2; } movws0(long m,long n) /* mov.w rm,@(r0,rn) */ { write_word(r[n]+r[0],r[m]); pc+=2; } movls0(long m,long n) /* mov.l rm,@(r0,rn) */ { write_long(r[n]+r[0],r[m]); pc+=2; } movbl0(long m,long n) /* mov.b @(r0,rm),rn */ { r[n]=(long)read_byte(r[m]+r[0]); if ((r[n]&0x80)==0) r[n]&0x000000ff; else r[n]|=0xffffff00; pc+=2; } movwl0(long m,long n) /* mov.w @(r0,rm),rn */ { r[n]=(long)read_word(r[m]+r[0]);
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 218 of 484 rej09b0051-0300 if ((r[n]&0x8000)==0) r[n]&0x0000ffff; else r[n]|=0xffff0000; pc+=2; } movll0(long m,long n) /* mov.l @(r0,rm),rn */ { r[n]=read_long(r[m]+r[0]); pc+=2; } example: mov r0,r1 ; before execution: r0 = h'ffffffff, r1 = h'00000000 ; after execution: r1 = h'ffffffff mov.w r0,@r1 ; before execution: r0 = h'ffff7f80 ; after execution: @r1 = h'7f80 mov.b @r0,r1 ; before execution: @r0 = h'80, r1 = h'00000000 ; after execution: r1 = h'ffffff80 mov.w r0,@?r1 ; before execution: r0 = h'aaaaaaaa, r1 = h'ffff7f80 ; after execution: r1 = h'ffff7f7e, @r1 = h'aaaa mov.l @r0+,r1 ; before execution: r0 = h'12345670 ; after execution: r0 = h'12345674, r1 = @h'12345670 mov.b r1,@(r0,r2) ; before execution: r2 = h'00000004, r0 = h'10000000 ; after execution: r1 = @h'10000004 mov.w @(r0,r2),r1 ; before execution: r2 = h'00000004, r0 = h'10000000 ; after execution: r1 = @h'10000004
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 219 of 484 rej09b0051-0300 6.4.31 mov move immediate data data transfer instruction immediate data transfer format abstract code cycle t bit mov #imm,rn imm sign extension rn 1110nnnniiiiiiii 1? mov.w @(disp, pc),rn (disp 2 + pc) sign extension rn 1001nnnndddddddd 1? mov.l @(disp, pc),rn (disp 4 + pc) rn 1101nnnndddddddd 1? description stores immediate data, which has been sign-extended to a longword, into general register rn. if the data is a word or longword, table data stored in the address specified by pc + displacement is accessed. if the data is a word, the 8-bit displacement is zero-extended and doubled. consequently, the relative interval from the table can be up to pc + 510 bytes. the pc points to the starting address of the fourth byte after this mov instruction. if the data is a longword, the 8- bit displacement is zero-extended and quadrupled. consequently, the relative interval from the table can be up to pc + 1020 bytes. the pc points to the starting address of the fourth byte after this mov instruction, but the lowest two bits of the pc are corrected to b'00. note the optimum table assignment is at the rear end of the module or one instruction after the unconditional branch instruction. if the optimum assignment is impossible for the reason of no unconditional branch instruction in the 510 byte/1020 byte or some other reason, means to jump past the table by the bra instruction are required. by assigning this instruction immediately after the delayed branch instruction, the pc becomes the "first address + 2". for the renesas technology super h risc engine assembler, declarations should use scaled values (2, 4) as displacement values.
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 220 of 484 rej09b0051-0300 operation movi(long i,long n) /* mov #imm,rn */ { if ((i&0x80)==0) r[n]=(0x000000ff & (long)i); else r[n]=(0xffffff00 | (long)i); pc+=2; } movwi(long d,long n) /* mov.w @(disp,pc),rn */ { long disp; disp=(0x000000ff & (long)d); r[n]=(long)read_word(pc+(disp<<1)); if ((r[n]&0x8000)==0) r[n]&=0x0000ffff; else r[n]|=0xffff0000; pc+=2; } movli(long d,long n) /* mov.l @(disp,pc),rn */ { long disp; disp=(0x000000ff & (long)d); r[n]=read_long((pc&0xfffffffc)+(disp<<2)); pc+=2; }
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 221 of 484 rej09b0051-0300 example: address 1000 mov #h'80,r1 ; r1 = h'ffffff80 1002 mov.w imm,r2 ; r2 = h'ffff9abc, imm means @(h'08,pc) 1004 add #?1,r0 ; 1006 tst r0,r0 ; pc location used for address calculation for the mov.w instruction 1008 movt r13 ; 100a bra next ; delayed branch instruction 100c mov.l @(4,pc),r3 ; r3 = h'12345678 100e imm .data.w h'9abc ; 1010 .data.w h'1234 ; 1012 next jmp @r3 ; branch destination of the bra instruction 1014 cmp/eq #0,r0 ; pc location used for address calculation for the mov.l instruction .align 4 ; 1018 .data.l h'12345678 ;
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 222 of 484 rej09b0051-0300 6.4.32 mov move peripheral data data transfer instruction peripheral module data transfer format abstract code cycle t bit mov.b @(disp,gbr),r0 (disp + gbr) sign extension r0 11000100dddddddd 1? mov.w @(disp,gbr),r0 (disp 2 + gbr) sign extension r0 11000101dddddddd 1? mov.l @(disp,gbr),r0 (disp 4 + gbr) r0 11000110dddddddd 1? mov.b r0,@(disp,gbr) r0 (disp + gbr) 11000000dddddddd 1? mov.w r0,@(disp,gbr) r0 (disp 2 + gbr) 11000001dddddddd 1? mov.l r0,@(disp,gbr) r0 (disp 4 + gbr) 11000010dddddddd 1? description transfers the source operand to the destination. this instruction is optimum for accessing data in the peripheral module area. the data can be a byte, word, or longword, but only the r0 register can be used. a peripheral module base address is set to the gbr. when the peripheral module data is a byte, the only change made is to zero-extend the 8-bit displacement. consequently, an address within +255 bytes can be specified. when the peripheral module data is a word, the 8-bit displacement is zero-extended and doubled. consequently, an address within +510 bytes can be specified. when the peripheral module data is a longword, the 8-bit displacement is zero-extended and is quadrupled. consequently, an address within +1020 bytes can be specified. if the displacement is too short to reach the memory operand, the above @(r0,rn) mode must be used after the gbr data is transferred to a general register. when the source operand is in memory, the loaded data is stored in the register after it is sign-extended to a longword. note the destination register of a data load is always r0. r0 cannot be accessed by the next instruction until the load instruction is finished. the instruction order shown in figure 6.1 will give better results. mov.b and add @(12, gbr), r0 #80, r0 #20, r1 mov.b add and @(12, gbr), r0 #20, r1 #80, r0 figure 6.1 using r0 after mov
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 223 of 484 rej09b0051-0300 for the renesas technology super h risc engine assembler, declarations should use scaled values (1, 2, 4) as displacement values. operation movblg(long d) /* mov.b @(disp,gbr),r0 */ { long disp; disp=(0x000000ff & (long)d); r[0]=(long)read_byte(gbr+disp); if ((r[0]&0x80)==0) r[0]&=0x000000ff; else r[0]|=0xffffff00; pc+=2; } movwlg(long d) /* mov.w @(disp,gbr),r0 */ { long disp; disp=(0x000000ff & (long)d); r[0]=(long)read_word(gbr+(disp<<1)); if ((r[0]&0x8000)==0) r[0]&=0x0000ffff; else r[0]|=0xffff0000; pc+=2; } movllg(long d) /* mov.l @(disp,gbr),r0 */ { long disp; disp=(0x000000ff & (long)d); r[0]=read_long(gbr+(disp<<2)); pc+=2; } movbsg(long d) /* mov.b r0,@(disp,gbr) */ { long disp;
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 224 of 484 rej09b0051-0300 disp=(0x000000ff & (long)d); write_byte(gbr+disp,r[0]); pc+=2; } movwsg(long d) /* mov.w r0,@(disp,gbr) */ { long disp; disp=(0x000000ff & (long)d); write_word(gbr+(disp<<1),r[0]); pc+=2; } movlsg(long d) /* mov.l r0,@(disp,gbr) */ { long disp; disp=(0x000000ff & (long)d); write_long(gbr+(disp<<2),r[0]); pc+=2; } examples: mov.l @(2,gbr),r0 ; before execution: @(gbr + 8) = h'12345670 ; after execution: r0 = h'12345670 mov.b r0,@(1,gbr) ; before execution: r0 = h'ffff7f80 ; after execution: @(gbr + 1) = h'ffff7f80
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 225 of 484 rej09b0051-0300 6.4.33 mov move structure data data transfer instruction structure data transfer format abstract code cycle t bit mov.b r0,@(disp,rn) r0 (disp + rn) 10000000nnnndddd 1? mov.w r0,@(disp,rn) r0 (disp 2 + rn) 10000001nnnndddd 1? mov.l rm,@(disp,rn) rm (disp 4 + rn) 0001nnnnmmmmdddd 1? mov.b @(disp,rm),r0 (disp + rm) sign extension r0 10000100mmmmdddd 1? mov.w @(disp,rm),r0 (disp 2 + rm) sign extension r0 10000101mmmmdddd 1? mov.l @(disp,rm),rn disp 4 + rm) rn 0101nnnnmmmmdddd 1? description transfers the source operand to the destination. this instruction is optimum for accessing data in a structure or a stack. the data can be a byte, word, or longword, but when a byte or word is selected, only the r0 register can be used. when the data is a byte, the only change made is to zero-extend the 4-bit displacement. consequently, an address within +15 bytes can be specified. when the data is a word, the 4-bit displacement is zero-extended and doubled. consequently, an address within +30 bytes can be specified. when the data is a longword, the 4-bit displacement is zero-extended and quadrupled. consequently, an address within +60 bytes can be specified. if the displacement is too short to reach the memory operand, the aforementioned @(r0,rn) mode must be used. when the source operand is in memory, the loaded data is stored in the register after it is sign-extended to a longword. note when byte or word data is loaded, the destination register is always r0. r0 cannot be accessed by the next instruction until the load instruction is finished. the instruction order in figure 6.2 will give better results. mov.b and add @(2, r1), r0 #80, r0 #20, r1 mov.b add and @(2, r1), r0 #20, r1 #80, r0 figure 6.2 using r0 after mov for the renesas technology superh risc engine assembler, declarations should use scaled values (1, 2, 4) as displacement values.
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 226 of 484 rej09b0051-0300 operation movbs4(long d,long n) /* mov.b r0,@(disp,rn) */ { long disp; disp=(0x0000000f & (long)d); write_byte(r[n]+disp,r[0]); pc+=2; } movws4(long d,long n) /* mov.w r0,@(disp,rn) */ { long disp; disp=(0x0000000f & (long)d); write_word(r[n]+(disp<<1),r[0]); pc+=2; } movls4(long m,long d,long n) /* mov.l rm,@(disp,rn) */ { long disp; disp=(0x0000000f & (long)d); write_long(r[n]+(disp<<2),r[m]); pc+=2; } movbl4(long m,long d) /* mov.b @(disp,rm),r0 */ { long disp; disp=(0x0000000f & (long)d); r[0]=read_byte(r[m]+disp); if ((r[0]&0x80)==0) r[0]&=0x000000ff; else r[0]|=0xffffff00; pc+=2; }
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 227 of 484 rej09b0051-0300 movwl4(long m,long d) /* mov.w @(disp,rm),r0 */ { long disp; disp=(0x0000000f & (long)d); r[0]=read_word(r[m]+(disp<<1)); if ((r[0]&0x8000)==0) r[0]&=0x0000ffff; else r[0]|=0xffff0000; pc+=2; } movll4(long m,long d,long n) /* mov.l @(disp,rm),rn */ { long disp; disp=(0x0000000f & (long)d); r[n]=read_long(r[m]+(disp<<2)); pc+=2; } examples: mov.l @(2,r0),r1 ; before execution: @(r0 + 8) = h'12345670 ; after execution: r1 = h'12345670 mov.l r0,@(h'f,r1) ; before execution: r0 = h'ffff7f80 ; after execution: @(r1 + 60) = h'ffff7f80
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 228 of 484 rej09b0051-0300 6.4.34 mova move effective address data transfer instruction effective address transfer format abstract code cycle t bit mova @(disp,pc),r0 disp 4 + pc r0 11000111dddddddd 1? description stores the effective address of the source operand into general register r0. the 8-bit displacement is zero-extended and quadrupled. consequently, the relative interval from the operand is pc + 1020 bytes. the pc is the address four bytes after this instruction, but the lowest two bits of the pc are corrected to b'00. note if this instruction is placed immediately after a delayed branch instruction, the pc must point to an address specified by (the starting address of the branch destination) + 2. for the renesas technology super h risc engine assembler, declarations should use scaled values (4) as displacement values. operation mova(long d) /* mova @(disp,pc),r0 */ { long disp; disp=(0x000000ff & (long)d); r[0]=(pc&0xfffffffc)+(disp<<2); pc+=2; }
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 229 of 484 rej09b0051-0300 example: address .org h'1006 1006 mova str,r0 ; address of str r0 1008 mov.b @r0,r1 ; r1 = ?x? pc location after correcting the lowest two bits 100a add r4,r5 ; original pc location for address calculation for the mova instruction .align 4 100c str: .sdata ?xyzp12? ............... 2002 bra trget ; delayed branch instruction 2004 mova @(0,pc),r0 ; address of trget + 2 r0 2006 nop ;
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 230 of 484 rej09b0051-0300 6.4.35 movt move t bit data transfer instruction t bit transfer format abstract code cycle t bit movt rn t rn 0000nnnn00101001 1? description stores the t bit value into general register rn. when t = 1, 1 is stored in rn, and when t = 0, 0 is stored in rn. operation movt(long n) /* movt rn */ { r[n]=(0x00000001 & sr); pc+=2; } example: xor r2,r2 ;r2 = 0 cmp/pz r2 ;t = 1 movt r0 ;r0 = 1 clrt ;t = 0 movt r1 ;r1 = 0
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 231 of 484 rej09b0051-0300 6.4.36 mul.l multiply long arithmetic instruction double-precision multiplication format abstract code cycle t bit mul.l rm,rn rn rm macl 0000nnnnmmmm0111 2? description performs 32-bit multiplication of the contents of general registers rn and rm, and stores the bottom 32 bits of the result in the macl register. the mach register data does not change. operation mul.l(long m,long n) /* mul.l rm,rn */ { macl=r[n]*r[m]; pc+=2; } example: mull r0,r1 ; before execution: r0 = h'fffffffe, r1 = h'00005555 ; after execution: macl = h'ffff5556 sts macl,r0 ; operation result
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 232 of 484 rej09b0051-0300 6.4.37 muls.w multiply as signed word arithmetic instruction signed multiplication format abstract code cycle t bit muls.w rm,rn muls rm,rn signed operation, rn rm macl 0010nnnnmmmm1111 1? description performs 16-bit multiplication of the contents of general registers rn and rm, and stores the 32- bit result in the macl register. the operation is signed and the mach register data does not change. operation muls(long m,long n) /* muls rm,rn */ { macl=((long)(short)r[n]*(long)(short)r[m]); pc+=2; } example: muls r0,r1 ; before execution: r0 = h'fffffffe, r1 = h'00005555 ; after execution: macl = h'ffff5556 sts macl,r0 ; operation result
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 233 of 484 rej09b0051-0300 6.4.38 mulu.w multiply as unsigned word arithmetic instruction unsigned multiplication format abstract code cycle t bit mulu.w rm,rn mulu rm,rn unsigned, rn rm macl 0010nnnnmmmm1110 1? description performs 16-bit multiplication of the contents of general registers rn and rm, and stores the 32- bit result in the macl register. the operation is unsigned and the mach register data does not change. operation mulu(long m,long n) /* mulu rm,rn */ { macl=((unsigned long)(unsigned short)r[n] *(unsigned long)(unsigned short)r[m]); pc+=2; } example: mulu r0,r1 ; before execution: r0 = h'00000002, r1 = h'ffffaaaa ; after execution: macl = h'00015554 sts macl,r0 ; operation result
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 234 of 484 rej09b0051-0300 6.4.39 neg negate arithmetic instruction sign inversion format abstract code cycle t bit neg rm,rn 0 ? rm rn 0110nnnnmmmm1011 1? description takes the two?s complement of data in general register rm, and stores the result in rn. this effectively subtracts rm data from 0, and stores the result in rn. operation neg(long m,long n) /* neg rm,rn */ { r[n]=0-r[m]; pc+=2; } example: neg r0,r1 ; before execution: r0 = h'00000001 ; after execution: r1 = h'ffffffff
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 235 of 484 rej09b0051-0300 6.4.40 negc negate with carry arithmetic instruction sign inversion with borrow format abstract code cycle t bit negc rm,rn 0 ? rm ? t rn, borrow t 0110nnnnmmmm1010 1 borrow description subtracts general register rm data and the t bit from 0, and stores the result in rn. if a borrow is generated, t bit changes accordingly. this instruction is used for inverting the sign of a value that has more than 32 bits. operation negc(long m,long n) /* negc rm,rn */ { unsigned long temp; temp=0-r[m]; r[n]=temp-t; if (0 section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 236 of 484 rej09b0051-0300 6.4.41 nop no operation system control instruction no operation format abstract code cycle t bit nop no operation 0000000000001001 1? description increments the pc to execute the next instruction. operation nop() /* nop */ { pc+=2; } example: nop ; executes in one cycle
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 237 of 484 rej09b0051-0300 6.4.42 not not-logical complement logical instruction bit inversion format abstract code cycle t bit not rm,rn ~rm rn 0110nnnnmmmm0111 1? description takes the one?s complement of general register rm data, and stores the result in rn. this effectively inverts each bit of rm data and stores the result in rn. operation not(long m,long n) /* not rm,rn */ { r[n]=~r[m]; pc+=2; } example: not r0,r1 ; before execution: r0 = h'aaaaaaaa ; after execution: r1 = h'55555555
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 238 of 484 rej09b0051-0300 6.4.43 or or logical logical instruction logical or format abstract code cycle t bit or rm,rn rn | rm rn 0010nnnnmmmm1011 1? or #imm,r0 r0 | imm r0 11001011iiiiiiii 1? or.b #imm,@(r0,gbr) (r0 + gbr) | imm (r0 + gbr) 11001111iiiiiiii 3? description logically ors the contents of general registers rn and rm, and stores the result in rn. the contents of general register r0 can also be ored with zero-extended 8-bit immediate data, or 8-bit memory data accessed by using indirect indexed gbr addressing can be ored with 8-bit immediate data. operation or(long m,long n) /* or rm,rn */ { r[n]|=r[m]; pc+=2; } ori(long i) /* or #imm,r0 */ { r[0]|=(0x000000ff & (long)i); pc+=2; } orm(long i) /* or.b #imm,@(r0,gbr) */ { long temp; temp=(long)read_byte(gbr+r[0]); temp|=(0x000000ff & (long)i); write_byte(gbr+r[0],temp); pc+=2; }
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 239 of 484 rej09b0051-0300 examples: or r0,r1 ; before execution: r0 = h'aaaa5555, r1 = h'55550000 ; after execution: r1 = h'ffff5555 or #h'f0,r0 ; before execution: r0 = h'00000008 ; after execution: r0 = h'000000f8 or.b #h'50,@(r0,gbr) ; before execution: @(r0,gbr) = h'a5 ; after execution: @(r0,gbr) = h'f5
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 240 of 484 rej09b0051-0300 6.4.44 rotcl rotate with carry left shift instruction one-bit left rotation through t bit format abstract code cycle t bit rotcl rn t rn t 0100nnnn00100100 1msb description rotates the contents of general register rn and the t bit to the left by one bit, and stores the result in rn. the bit that is shifted out of the operand is transferred to the t bit (figure 6.3). lsb msb t rotcl figure 6.3 rotate with carry left operation rotcl(long n) /* rotcl rn */ { long temp; if ((r[n]&0x80000000)==0) temp=0; else temp=1; r[n]<<=1; if (t==1) r[n]|=0x00000001; else r[n]&=0xfffffffe; if (temp==1) t=1; else t=0; pc+=2; } example: rotcl r0 ; before execution: r0 = h'80000000, t = 0 ; after execution: r0 = h'00000000, t = 1
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 241 of 484 rej09b0051-0300 6.4.45 rotcr rotate with carry right shift instruction one-bit right rotation through t bit format abstract code cycle t bit rotcr rn t rn t 0100nnnn00100101 1lsb description rotates the contents of general register rn and the t bit to the right by one bit, and stores the result in rn. the bit that is shifted out of the operand is transferred to the t bit (figure 6.4). lsb msb t rotcr figure 6.4 rotate with carry right operation rotcr(long n) /* rotcr rn */ { long temp; if ((r[n]&0x00000001)==0) temp=0; else temp=1; r[n]>>=1; if (t==1) r[n]|=0x80000000; else r[n]&=0x7fffffff; if (temp==1) t=1; else t=0; pc+=2; } examples: rotcr r0 ; before execution: r0 = h'00000001, t = 1 ; after execution: r0 = h'80000000, t = 1
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 242 of 484 rej09b0051-0300 6.4.46 rotl rotate left shift instruction one-bit left rotation format abstract code cycle t bit rotl rn t rn msb 0100nnnn00000100 1msb description rotates the contents of general register rn to the left by one bit, and stores the result in rn (figure 6.5). the bit that is shifted out of the operand is transferred to the t bit. lsb msb t rotl figure 6.5 rotate left operation rotl(long n) /* rotl rn */ { if ((r[n]&0x80000000)==0) t=0; else t=1; r[n]<<=1; if (t==1) r[n]|=0x00000001; else r[n]&=0xfffffffe; pc+=2; } examples: rotl r0 ; before execution: r0 = h'80000000, t = 0 ; after execution: r0 = h'00000001, t = 1
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 243 of 484 rej09b0051-0300 6.4.47 rotr rotate right shift instruction one-bit right rotation format abstract code cycle t bit rotr rn lsb rn t 0100nnnn00000101 1lsb description rotates the contents of general register rn to the right by one bit, and stores the result in rn (figure 6.6). the bit that is shifted out of the operand is transferred to the t bit. lsb msb t rotr figure 6.6 rotate right operation rotr(long n) /* rotr rn */ { if ((r[n]&0x00000001)==0) t=0; else t=1; r[n]>>=1; if (t==1) r[n]|=0x80000000; else r[n]&=0x7fffffff; pc+=2; } examples: rotr r0 ; before execution: r0 = h'00000001, t = 0 ; after execution: r0 = h'80000000, t = 1
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 244 of 484 rej09b0051-0300 6.4.48 rte return from exception system control instruction return from exception handling delayed branch instruction format abstract code cycle t bit rte delayed branch, stack area pc/sr 0000000000101011 4lsb description returns from an interrupt routine. the pc and sr values are restored from the stack, and the program continues from the address specified by the restored pc value. the t bit is used as the lsb bit in the sr register restored from the stack area. note since this is a delayed branch instruction, the instruction after this rte is executed before branching. no address errors and interrupts are accepted between this instruction and the next instruction. if the next instruction is a branch instruction, it is acknowledged as an illegal slot instruction. operation rte() /* rte */ { unsigned long temp; temp=pc; pc=read_long(r[15])+4; r[15]+=4; sr=read_long(r[15])&0x000063f3; r[15]+=4; delay_slot(temp+2); }
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 245 of 484 rej09b0051-0300 example: rte ; returns to the original routine add #8,r14 ; executes add before branching note: when a delayed branch instruction is used, the branching operation takes place after the slot instruction is executed, but the execution of instructions (register update, etc.) takes place in the sequence delayed branch instruction delayed slot instruction. for example, even if a delayed slot instruction is used to change the register where the branch destination address is stored, the register content previous to the change will be used as the branch destination address.
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 246 of 484 rej09b0051-0300 6.4.49 rts return from subroutine branch instruction return from subroutine procedure delayed branch instruction format abstract code cycle t bit rts delayed branch, pr pc 0000000000001011 2? description returns from a subroutine procedure. the pc values are restored from the pr, and the program continues from the address specified by the restored pc value. this instruction is used to return to the program from a subroutine program called by a bsr, bsrf, or jsr instruction. note since this is a delayed branch instruction, the instruction after this rts is executed before branching. no address errors and interrupts are accepted between this instruction and the next instruction. if the next instruction is a branch instruction, it is acknowledged as an illegal slot instruction. operation rts() /* rts */ { unsigned long temp; temp=pc; pc=pr+4; delay_slot(temp+2); }
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 247 of 484 rej09b0051-0300 example: mov.l table,r3 ; r3 = address of trget jsr @r3 ; branches to trget nop ; executes nop before branching add r0,r1 ; return address for when the subroutine procedure is completed (pr data) ............. table: .data.l trget ; ............. trget: mov r1,r0 ; procedure entrance rts ; pr data pc mov #12,r0 ; executes mov before branching note: when a delayed branch instruction is used, the branching operation takes place after the slot instruction is executed, but the execution of instructions (register update, etc.) takes place in the sequence delayed branch instruction delayed slot instruction. for example, even if a delayed slot instruction is used to change the register where the branch destination address is stored, the register content previous to the change will be used as the branch destination address.
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 248 of 484 rej09b0051-0300 6.4.50 sett set t bit system control instruction t bit setting format abstract code cycle t bit sett 1 t 0000000000011000 11 description sets the t bit to 1. operation sett() /* sett */ { t=1; pc+=2; } example: sett ; before execution: t = 0 ; after execution: t = 1
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 249 of 484 rej09b0051-0300 6.4.51 shal shift arithmetic left shift instruction one-bit left arithmetic shift format abstract code cycle t bit shal rn t rn 0 0100nnnn00100000 1msb description arithmetically shifts the contents of general register rn to the left by one bit, and stores the result in rn. the bit that is shifted out of the operand is transferred to the t bit (figure 6.7). lsb msb t0 shal figure 6.7 shift arithmetic left operation shal(long n) /* shal rn (same as shll) */ { if ((r[n]&0x80000000)==0) t=0; else t=1; r[n]<<=1; pc+=2; } example: shal r0 ; before execution: r0 = h'80000001, t = 0 ; after execution: r0 = h'00000002, t = 1
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 250 of 484 rej09b0051-0300 6.4.52 shar shift arithmetic right shift instruction one-bit right arithmetic shift format abstract code cycle t bit shar rn msb rn t 0100nnnn00100001 1lsb description arithmetically shifts the contents of general register rn to the right by one bit, and stores the result in rn. the bit that is shifted out of the operand is transferred to the t bit (figure 6.8). lsb msb t shar figure 6.8 shift arithmetic right operation shar(long n) /* shar rn */ { long temp; if ((r[n]&0x00000001)==0) t=0; else t=1; if ((r[n]&0x80000000)==0) temp=0; else temp=1; r[n]>>=1; if (temp==1) r[n]|=0x80000000; else r[n]&=0x7fffffff; pc+=2; } example: shar r0 ; before execution: r0 = h'80000001, t = 0 ; after execution: r0 = h'c0000000, t = 1
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 251 of 484 rej09b0051-0300 6.4.53 shll shift logical left shift instruction one-bit left logical shift format abstract code cycle t bit shll rn t rn 0 0100nnnn00000000 1msb description logically shifts the contents of general register rn to the left by one bit, and stores the result in rn. the bit that is shifted out of the operand is transferred to the t bit (figure 6.9). lsb msb t0 shll figure 6.9 shift logical left operation shll(long n) /* shll rn (same as shal) */ { if ((r[n]&0x80000000)==0) t=0; else t=1; r[n]<<=1; pc+=2; } examples: shll r0 ; before execution: r0 = h'80000001, t = 0 ; after execution: r0 = h'00000002, t = 1
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 252 of 484 rej09b0051-0300 6.4.54 shlln n bits shift logical left shift instruction n-bit left logical shift format abstract code cycle t bit shll2 rn rn << 2 rn 0100nnnn00001000 1? shll8 rn rn << 8 rn 0100nnnn00011000 1? shll16 rn rn << 16 rn 0100nnnn00101000 1? description logically shifts the contents of general register rn to the left by 2, 8, or 16 bits, and stores the result in rn. bits that are shifted out of the operand are not stored (figure 6.10). 0 0 0 msb lsb msb lsb msb lsb shll2 shll8 shll16 figure 6.10 shift logical left n bits
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 253 of 484 rej09b0051-0300 operation shll2(long n) /* shll2 rn */ { r[n]<<=2; pc+=2; } shll8(long n) /* shll8 rn */ { r[n]<<=8; pc+=2; } shll16(long n) /* shll16 rn */ { r[n]<<=16; pc+=2; } examples: shll2 r0 ; before execution: r0 = h'12345678 ; after execution: r0 = h'48d159e0 shll8 r0 ; before execution: r0 = h'12345678 ; after execution: r0 = h'34567800 shll16 r0 ; before execution: r0 = h'12345678 ; after execution: r0 = h'56780000
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 254 of 484 rej09b0051-0300 6.4.55 shlr shift logical right shift instruction one-bit right logical shift format abstract code cycle t bit shlr rn 0 rn t 0100nnnn00000001 1lsb description logically shifts the contents of general register rn to the right by one bit, and stores the result in rn. the bit that is shifted out of the operand is transferred to the t bit (figure 6.11). lsb msb t 0 shlr figure 6.11 shift logical right operation shlr(long n) /* shlr rn */ { if ((r[n]&0x00000001)==0) t=0; else t=1; r[n]>>=1; r[n]&=0x7fffffff; pc+=2; } examples: shlr r0 ; before execution: r0 = h'80000001, t = 0 ; after execution: r0 = h'40000000, t = 1
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 255 of 484 rej09b0051-0300 6.4.56 shlrn n bits shift logical right shift instruction n-bit right logical shift format abstract code cycle t bit shlr2 rn rn>>2 rn 0100nnnn00001001 1? shlr8 rn rn>>8 rn 0100nnnn00011001 1? shlr16 rn rn>>16 rn 0100nnnn00101001 1? description logically shifts the contents of general register rn to the right by 2, 8, or 16 bits, and stores the result in rn. bits that are shifted out of the operand are not stored (figure 6.12). 0 0 0 msb lsb msb lsb msb lsb shlr2 shlr8 shlr16 figure 6.12 shift logical right n bits
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 256 of 484 rej09b0051-0300 operation shlr2(long n) /* shlr2 rn */ { r[n]>>=2; r[n]&=0x3fffffff; pc+=2; } shlr8(long n) /* shlr8 rn */ { r[n]>>=8; r[n]&=0x00ffffff; pc+=2; } shlr16(long n) /* shlr16 rn */ { r[n]>>=16; r[n]&=0x0000ffff; pc+=2; } examples: shlr2 r0 ; before execution: r0 = h'12345678 ; after execution: r0 = h'048d159e shlr8 r0 ; before execution: r0 = h'12345678 ; after execution: r0 = h'00123456 shlr16 r0 ; before execution: r0 = h'12345678 ; after execution: r0 = h'00001234
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 257 of 484 rej09b0051-0300 6.4.57 sleep sleep system control instruction transition to power-down mode format abstract code cycle t bit sleep sleep 0000000000011011 5? description sets the cpu into power-down mode. in power-down mode, instruction execution stops, but the cpu internal status is maintained, and the cpu waits for an interrupt request. if an interrupt is requested, the cpu exits the power-down mode and begins exception processing. note the number of cycles given is for the transition to sleep mode. operation sleep() /* sleep */ { wait_for_exception; } example: sleep ; enters power-down mode
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 258 of 484 rej09b0051-0300 6.4.58 stc store control register system control instruction store from control register format abstract code cycle t bit stc sr,rn sr rn 0000nnnn00000010 2? stc gbr,rn gbr rn 0000nnnn00010010 1? stc vbr,rn vbr rn 0000nnnn00100010 1? stc.l sr,@-rn rn ? 4 rn, sr (rn) 0100nnnn00000011 2? stc.l gbr,@-rn rn ? 4 rn, gbr (rn) 0100nnnn00010011 1? stc.l vbr,@-rn rn ? 4 rn, vbr (rn) 0100nnnn00100011 1? description stores control register sr, gbr, or vbr data into a specified destination. operation stcsr(long n) /* stc sr,rn */ { r[n]=sr; pc+=2; } stcgbr(long n) /* stc gbr,rn */ { r[n]=gbr; pc+=2; } stcvbr(long n) /* stc vbr,rn */ { r[n]=vbr; pc+=2; } stcmsr(long n) /* stc.l sr,@-rn */ { r[n]-=4; write_long(r[n],sr);
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 259 of 484 rej09b0051-0300 pc+=2; } stcmgbr(long n) /* stc.l gbr,@-rn */ { r[n]-=4; write_long(r[n],gbr); pc+=2; } stcmvbr(long n) /* stc.l vbr,@-rn */ { r[n]-=4; write_long(r[n],vbr); pc+=2; } examples: stc sr,r0 ; before execution: r0 = h'ffffffff, sr = h'00000000 ; after execution: r0 = h'00000000 stc.l gbr,@-r15 ; before execution: r15 = h'10000004 ; after execution: r15 = h'10000000, @r15 = gbr
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 260 of 484 rej09b0051-0300 6.4.59 sts store system register system control instruction store from system register format abstract code cycle t bit sts mach,rn mach rn 0000nnnn00001010 1? sts macl,rn macl rn 0000nnnn00011010 1? sts pr,rn pr rn 0000nnnn00101010 1? sts.l mach,@?rn rn ? 4 rn, mach (rn) 0100nnnn00000010 1? sts.l macl,@?rn rn ? 4 rn, macl (rn) 0100nnnn00010010 1? sts.l pr,@?rn rn ? 4 rn, pr (rn) 0100nnnn00100010 1? description stores data from system register mach, macl, or pr into a specified destination. operation stsmach(long n) /* sts mach,rn */ { r[n]=mach; pc+=2; } stsmacl(long n) /* sts macl,rn */ { r[n]=macl; pc+=2; } stspr(long n) /* sts pr,rn */ { r[n]=pr; pc+=2; } stsmmach(long n) /* sts.l mach,@?rn */ { r[n]?=4;
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 261 of 484 rej09b0051-0300 write_long(r[n],mach); pc+=2; } stsmmacl(long n) /* sts.l macl,@?rn */ { r[n]?=4; write_long(r[n],macl); pc+=2; } stsmpr(long n) /* sts.l pr,@?rn */ { r[n]?=4; write_long(r[n],pr); pc+=2; } example: sts mach,r0 ; before execution: r0 = h'ffffffff, mach = h'00000000 ; after execution: r0 = h'00000000 sts.l pr,@?r15 ; before execution: r15 = h'10000004 ; after execution: r15 = h'10000000, @r15 = pr
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 262 of 484 rej09b0051-0300 6.4.60 sub subtract binary arithmetic instruction binary subtraction format abstract code cycle t bit sub rm,rn rn ? rm rn 0011nnnnmmmm1000 1? description subtracts general register rm data from rn data, and stores the result in rn. to subtract immediate data, use add #imm,rn. operation sub(long m,long n) /* sub rm,rn */ { r[n]-=r[m]; pc+=2; } example: sub r0,r1 ; before execution: r0 = h'00000001, r1 = h'80000000 ; after execution: r1 = h'7fffffff
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 263 of 484 rej09b0051-0300 6.4.61 subc subtract with carry arithmetic instruction binary subtraction with borrow format abstract code cycle t bit subc rm,rn rn ? rm? t rn, borrow t 0011nnnnmmmm1010 1 borrow description subtracts rm data and the t bit value from general register rn data, and stores the result in rn. the t bit changes according to the result. this instruction is used for subtraction of data that has more than 32 bits. operation subc(long m,long n) /* subc rm,rn */ { unsigned long tmp0,tmp1; tmp1=r[n]-r[m]; tmp0=r[n]; r[n]=tmp1-t; if (tmp0 section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 264 of 484 rej09b0051-0300 6.4.62 subv subtract with (v flag) underflow check arithmetic instruction binary subtraction with underflow check format abstract code cycle t bit subv rm,rn rn ? rm rn, underflow t 0011nnnnmmmm1011 1 underflow description subtracts rm data from general register rn data, and stores the result in rn. if an underflow occurs, the t bit is set to 1. operation subv(long m,long n) /* subv rm,rn */ { long dest,src,ans; if ((long)r[n]>=0) dest=0; else dest=1; if ((long)r[m]>=0) src=0; else src=1; src+=dest; r[n]-=r[m]; if ((long)r[n]>=0) ans=0; else ans=1; ans+=dest; if (src==1) { if (ans==1) t=1; else t=0; } else t=0; pc+=2; }
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 265 of 484 rej09b0051-0300 examples: subv r0,r1 ; before execution: r0 = h'00000002, r1 = h'80000001 ; after execution: r1 = h'7fffffff, t = 1 subv r2,r3 ; before execution: r2 = h'fffffffe, r3 = h'7ffffffe ; after execution: r3 = h'80000000, t = 1
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 266 of 484 rej09b0051-0300 6.4.63 swap swap register halves data transfer instruction upper-/lower-half swap format abstract code cycle t bit swap.b rm,rn rm swap upper and lower halves of lower 2 bytes rn 0110nnnnmmmm1000 1? swap.w rm,rn rm swap upper and lower word rn 0110nnnnmmmm1001 1? description swaps the upper and lower bytes of the general register rm data, and stores the result in rn. if a byte is specified, bits 0 to 7 of rm are swapped for bits 8 to 15. the upper 16 bits of rm are transferred to the upper 16 bits of rn. if a word is specified, bits 0 to 15 of rm are swapped for bits 16 to 31. operation swapb(long m,long n) /* swap.b rm,rn */ { unsigned long temp0,temp1; temp0=r[m]&0xffff0000; temp1=(r[m]&0x000000ff)<<8; r[n]=(r[m]>>8)&0x000000ff; r[n]=r[n]|temp1|temp0; pc+=2; } swapw(long m,long n) /* swap.w rm,rn */ { unsigned long temp; temp=(r[m]>>16)&0x0000ffff; r[n]=r[m]<<16; r[n]|=temp; pc+=2; }
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 267 of 484 rej09b0051-0300 examples: swap.b r0,r1 ; before execution: r0 = h'12345678 ; after execution: r1 = h'12347856 swap.w r0,r1 ; before execution: r0 = h'12345678 ; after execution: r1 = h'56781234
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 268 of 484 rej09b0051-0300 6.4.64 tas test and set logical instruction memory test and bit setting format abstract code cycle t bit tas.b @rn when (rn) is 0, 1 t, 1 msb of (rn) 0100nnnn00011011 3 test results description reads byte data from the address specified by general register rn, and sets the t bit to 1 if the data is 0, or clears the t bit to 0 if the data is not 0. then, data bit 7 is set to 1, and the data is written to the address specified by rn. during this operation, the bus is not released. operation tas(long n) /* tas.b @rn */ { long temp; temp=(long)read_byte(r[n]); /* bus lock enable */ if (temp==0) t=1; else t=0; temp|=0x00000080; write_byte(r[n],temp); /* bus lock disable */ pc+=2; } example: _loop tas.b @r7 ; r7 = 1000 bf _loop ; loops until data in address 1000 is 0
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 269 of 484 rej09b0051-0300 6.4.65 trapa trap always system control instruction trap exception handling format abstract code cycle t bit trapa #imm pc/sr stack area, (imm 4 + vbr) pc 11000011iiiiiiii 5? description starts the trap exception processing. the pc and sr values are stored on the stack, and the program branches to an address specified by the vector. the vector is a memory address obtained by zero-extending the 8-bit immediate data and then quadrupling it. the pc is the start address of the next instruction. trapa and rte are both used together for system calls. note for the renesas technology super h risc engine assembler, declarations should use scaled values (4) as displacement values. operation trapa(long i) /* trapa #imm */ { long imm; imm=(0x000000ff & i); r[15]-=4; write_long(r[15],sr); r[15]-=4; write_long(r[15],pc?2); pc=read_long(vbr+(imm<<2))+4; }
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 270 of 484 rej09b0051-0300 example: address vbr+h'80 .data.l 10000000 ; .......... trapa #h'20 ; branches to an address specified by data in address vbr + h'80 tst #0,r0 ; return address from the trap routine (stacked pc value) ........... .......... 100000000 xor r0,r0 ; trap routine entrance 100000002 rte ; returns to the tst instruction 100000004 nop ; executes nop before rte
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 271 of 484 rej09b0051-0300 6.4.66 tst test logical logical instruction and operation t bit setting format abstract code cycle t bit tst rm,rn rn & rm, when result is 0, 1 t 0010nnnnmmmm1000 1test results tst #imm,r0 r0 & imm, when result is 0, 1 t 11001000iiiiiiii 1test results tst.b #imm, @(r0,gbr) (r0 + gbr) & imm, when result is 0, 1 t 11001100iiiiiiii 3test results description logically ands the contents of general registers rn and rm, and sets the t bit to 1 if the result is 0 or clears the t bit to 0 if the result is not 0. the rn data does not change. the contents of general register r0 can also be anded with zero-extended 8-bit immediate data, or the contents of 8-bit memory accessed by indirect indexed gbr addressing can be anded with 8-bit immediate data. the r0 and memory data do not change. operation tst(long m,long n) /* tst rm,rn */ { if ((r[n]&r[m])==0) t=1; else t=0; pc+=2; } tsti(long i) /* test #imm,r0 */ { long temp; temp=r[0]&(0x000000ff & (long)i); if (temp==0) t=1; else t=0; pc+=2; } tstm(long i) /* tst.b #imm,@(r0,gbr) */
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 272 of 484 rej09b0051-0300 { long temp; temp=(long)read_byte(gbr+r[0]); temp&=(0x000000ff & (long)i); if (temp==0) t=1; else t=0; pc+=2; } examples: tst r0,r0 ; before execution: r0 = h'00000000 ; after execution: t = 1 tst #h'80,r0 ; before execution: r0 = h'ffffff7f ; after execution: t = 1 tst.b #h'a5,@(r0,gbr) ; before execution: @(r0,gbr) = h'a5 ; after execution: t = 0
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 273 of 484 rej09b0051-0300 6.4.67 xor exclusive or logical logical instruction exclusive logical or format abstract code cycle t bit xor rm,rn rn ^ rm rn 0010nnnnmmmm1010 1? xor #imm,r0 r0 ^ imm r0 11001010iiiiiiii 1? xor.b #imm, @(r0,gbr) (r0 + gbr) ^ imm (r0 + gbr) 11001110iiiiiiii 3? description exclusive ors the contents of general registers rn and rm, and stores the result in rn. the contents of general register r0 can also be exclusive ored with zero-extended 8-bit immediate data, or 8-bit memory accessed by indirect indexed gbr addressing can be exclusive ored with 8-bit immediate data.
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 274 of 484 rej09b0051-0300 operation xor(long m,long n) /* xor rm,rn */ { r[n]^=r[m]; pc+=2; } xori(long i) /* xor #imm,r0 */ { r[0]^=(0x000000ff & (long)i); pc+=2; } xorm(long i) /* xor.b #imm,@(r0,gbr) */ { long temp; temp=(long)read_byte(gbr+r[0]); temp^=(0x000000ff & (long)i); write_byte(gbr+r[0],temp); pc+=2; } examples: xor r0,r1 ; before execution: r0 = h'aaaaaaaa, r1 = h'55555555 ; after execution: r1 = h'ffffffff xor #h'f0,r0 ; before execution: r0 = h'ffffffff ; after execution: r0 = h'ffffff0f xor.b #h'a5,@(r0,gbr) ; before execution: @(r0,gbr) = h'a5 ; after execution: @(r0,gbr) = h'00
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 275 of 484 rej09b0051-0300 6.4.68 xtrct extract data transfer instruction middle extraction from linked registers format abstract code cycle t bit xtrct rm,rn rm: center 32 bits of rn rn 0010nnnnmmmm1101 1? description extracts the middle 32 bits from the 64 bits of coupled general registers rm and rn, and stores the 32 bits in rn (figure 6.13). rm rn rn msb msb lsb lsb figure 6.13 extract operation xtrct(long m,long n) /* xtrct rm,rn */ { unsigned long temp; temp=(r[m]<<16)&0xffff0000; r[n]=(r[n]>>16)&0x0000ffff; r[n]|=temp; pc+=2; } example: xtrct r0,r1 ; before execution: r0 = h'01234567, r1 = h'89abcdef ; after execution: r1 = h'456789ab
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 276 of 484 rej09b0051-0300 6.5 floating-point instructions and fpu-related cpu instructions 6.5.1 fabs floating-point absolute value floating-point instruction floating-point absolute value pr format abstract code cycle t bit 0 fabs frn |frn| frn 1111nnnn01011101 1? 1 fabs drn |drn| drn 1111nnn001011101 1? description this instruction clears the most significant bit of the contents of floating-point register frn/drn to 0, and stores the result in frn/drn. the cause and flag fields in fpscr are not updated. operation void fabs (int n){ fr[n] = fr[n] & 0x7fffffff; pc += 2; } /* same operation is performed regardless of precision. */ possible exceptions: none
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 277 of 484 rej09b0051-0300 6.5.2 fadd floating-point add floating-point instruction floating-point addition pr format abstract code cycle t bit 0 fadd frm,frn frn+frm frn 1111nnnnmmmm0000 1? 1 fadd drm,drn drn+drm drn 1111nnn0mmm00000 6? description when fpscr.pr = 0: arithmetically adds the two single-precision floating-point numbers in frn and frm, and stores the result in frn. when fpscr.pr = 1: arithmetically adds the two double-precision floating-point numbers in drn and drm, and stores the result in drn. when fpscr.enable.o/u/i is set, an fpu exception trap is generated regardless of whether or not an exception has occurred. when an exception occurs, correct exception information is reflected in fpscr.cause and fpscr.flag, and frn or drn is not updated. appropriate processing should therefore be performed by software. operation void fadd (int m,n) { pc += 2; clear_cause(); if((data_type_of(m) == snan) || (data_type_of(n) == snan)) invalid(n); else if((data_type_of(m) == qnan) || (data_type_of(n) == qnan)) qnan(n); else if((data_type_of(m) == denorm) || (data_type_of(n) == denorm)) set_e(); else switch (data_type_of(m)){ case norm: switch (data_type_of(n)){ case norm: normal_faddsub(m,n,add); break; case pzero:
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 278 of 484 rej09b0051-0300 case nzero:register_copy(m,n); break; default: break; } break; case pzero: switch (data_type_of(n)){ case nzero: zero(n,0); break; default: break; } break; case nzero: break; case pinf: switch (data_type_of(n)){ case ninf: invalid(n); break; default: inf(n,0); break; } break; case ninf: switch (data_type_of(n)){ case pinf: invalid(n); break; default: inf(n,1); break; } break; } } fadd special cases frm,drm frn,drn norm +0 ?0 +inf ?inf qnan snan norm add ?inf +0 +0 ?0 ?0 +inf +inf invalid ?inf ?inf invalid ?inf qnan qnan snan invalid note: when dn = 1, the value of a denormalized number is treated as 0.
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 279 of 484 rej09b0051-0300 possible exceptions: ? invalid operation ? overflow ? underflow ? inexact
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 280 of 484 rej09b0051-0300 6.5.3 fcmp floating-point compare floating-point instruction floating-point comparison no. pr format abstract code cycle t bit 1. 0 fcmp/eq frm,frn (frn==frm)?1:0 t 1111nnnnmmmm0100 11/0 2. 1 fcmp/eq drm,drn (drn==drm)?1:0 t 1111nnn0mmm00100 21/0 3. 0 fcmp/gt frm,frn (frn>frm)?1:0 t 1111nnnnmmmm0101 11/0 4. 1 fcmp/gt drm,drn (drn>drm)?1:0 t 1111nnn0mmm00101 21/0 description 1. when fpscr.pr = 0: arithmetically compares the two single-precision floating-point numbers in frn and frm, and stores 1 in the t bit if they are equal, or 0 otherwise. 2. when fpscr.pr = 1: arithmetically compares the two double-precision floating-point numbers in drn and drm, and stores 1 in the t bit if they are equal, or 0 otherwise. 3. when fpscr.pr = 0: arithmetically compares the two single-precision floating-point numbers in frn and frm, and stores 1 in the t bit if frn > frm, or 0 otherwise. 4. when fpscr.pr = 1: arithmetically compares the two double-precision floating-point numbers in drn and drm, and stores 1 in the t bit if drn > drm, or 0 otherwise. operation void fcmp_eq(int m,n) /* fcmp/eq frm,frn */ { pc += 2; clear_cause(); if(fcmp_chk (m,n) == invalid) fcmp_invalid(); else if(fcmp_chk (m,n) == eq) t = 1; else t = 0; } void fcmp_gt(int m,n) /* fcmp/gt frm,frn */ { pc += 2; clear_cause(); if ((fcmp_chk (m,n) == invalid) || (fcmp_chk (m,n) == uo)) fcmp_invalid();
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 281 of 484 rej09b0051-0300 else if(fcmp_chk (m,n) == gt) t = 1; else t = 0; } int fcmp_chk (int m,n) { if((data_type_of(m) == snan) || (data_type_of(n) == snan)) return(invalid); else if((data_type_of(m) == qnan) || (data_type_of(n) == qnan)) return(uo); else switch(data_type_of(m)){ case norm: switch(data_type_of(n)){ case pinf :return(gt); break; case ninf :return(lt); break; default: break; } break; case pzero: case nzero: switch(data_type_of(n)){ case pzero : case nzero :return(eq); break; default: break; } break; case pinf : switch(data_type_of(n)){ case pinf :return(eq); break; default:return(lt); break; } break; case ninf : switch(data_type_of(n)){ case ninf :return(eq); break; default:return(gt); break; } break; } if(fpscr_pr == 0) { if(fr[n] == fr[m]) return(eq); else if(fr[n] > fr[m]) return(gt); else return(lt); }else {
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 282 of 484 rej09b0051-0300 if(dr[n>>1] == dr[m>>1]) return(eq); else if(dr[n>>1] > dr[m>>1]) return(gt); else return(lt); } } void fcmp_invalid() { set_v(); t = 0; if((fpscr & enable_v)==1) fpu_exception_trap(); } fcmp special cases fcmp/eq frn,drn frm,drm norm +0 ?0 +inf ?inf qnan snan norm cmp +0 eq ?0 +inf eq ?inf eq qnan !eq snan invalid note: the value of a denormalized number is treated as 0. fcmp/gt frn,drn frm,drm norm +0 ?0 +inf ?inf qnan snan norm cmp gt !gt +0 !gt ?0 +inf !gt !gt ?inf gt !gt qnan uo snan invalid note: the value of a denormalized number is treated as 0. uo means unordered. unordered is treated as false (!gt).
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 283 of 484 rej09b0051-0300 possible exceptions: invalid operation
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 284 of 484 rej09b0051-0300 6.5.4 fcnvds floating-point convert double to single precision floating-point instruction double-precision to single-precision conversion pr format abstract code cycle t bit 0? ? ? ? ? 1 fcnvds drm,fpul (float)drm fpul 1111mmm010111101 2? description when fpscr.pr = 1, this instruction converts the double-precision floating-point number in drm to a single-precision floating-point number, and stores the result in fpul. when fpscr.enable.o/u/i is set, an fpu exception trap is generated regardless of whether or not an exception has occurred. when an exception occurs, correct exception information is reflected in fpscr.cause and fpscr.flag, and fpul is not updated. appropriate processing should therefore be performed by software. if fpscr.pr = 0, the instruction is handled as an illegal instruction. operation void fcnvds(int m, float *fpul){ case((fpscr.pr){ 0: undefined_operation(); /* reserved */ 1: fcnvds(m, *fpul); break; /* fcnvds */ } } void fcnvds(int m, float *fpul) { pc += 2; clear_cause(); case(data_type_of(m, *fpul)){ norm : pzero : nzero : normal_ fcnvds(m, *fpul); break;
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 285 of 484 rej09b0051-0300 pinf : *fpul = 0x7f800000; break; ninf : *fpul = 0xff800000; break; qnan : *fpul = 0x7fbfffff; break; snan : set_v(); if((fpscr & enable_v) == 0) *fpul = 0x7fbfffff; else fpu_exception_trap(); break; } } void normal_fcnvds(int m, float *fpul) { int sign; float abs; union { float f; int l; } dstf,tmpf; union { double d; int l[2]; } dstd; dstd.d = dr[m>>1]; if(dstd.l[1] & 0x1fffffff)) set_i(); if(fpscr_rm == 1) dstd.l[1] &= 0xe0000000; /* round toward zero*/ dstf.f = dstd.d; check_single_exception(fpul, dstf.f); } fcnvds special cases frn +norm ?norm +0 ?0 +inf ?inf qnan snan fcnvds(frn fpul) fcnvds fcnvds +0 ?0 +inf ?inf qnan invalid note: the value of a denormalized number is treated as 0.
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 286 of 484 rej09b0051-0300 possible exceptions: ? invalid operation ? overflow ? underflow ? inexact
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 287 of 484 rej09b0051-0300 6.5.5 fcnvsd floating-point convert single to double precision floating-point instruction single-precision to double-precision conversion pr format abstract code cycle t bit 0? ? ? ? ? 1 fcnvsd fpul, drn (double) fpul drn 1111nnn010101101 2? description when fpscr.pr = 1, this instruction converts the single-precision floating-point number in fpul to a double-precision floating-point number, and stores the result in drn. if fpscr.pr = 0, the instruction is handled as an illegal instruction. operation void fcnvsd(int n, float *fpul){ pc += 2; clear_cause(); case((fpscr_pr){ 0: undefined_operation(); /* reserved */ 1: fcnvsd (n, *fpul); break; /* fcnvsd */ } } void fcnvsd(int n, float *fpul) { case(fpul_type(fpul)){ pzero : nzero : pinf : ninf : dr[n>>1] = *fpul; break; qnan : qnan(n); break; snan : invalid(n); break; }
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 288 of 484 rej09b0051-0300 } int fpul_type(int *fpul) { int abs; abs = *fpul & 0x7fffffff; if(abs < 0x00800000){ if((fpscr_dn == 1) || (abs == 0x00000000)){ if(sign_of(src) == 0) return(pzero); else return(nzero); } else return(denorm); } else if(abs < 0x7f800000) return(norm); else if(abs == 0x7f800000) { if(sign_of(src) == 0) return(pinf); else return(ninf); } else if(abs < 0x7fc00000) return(qnan); else return(snan); } fcnvsd special cases frn +norm ?norm +0 ?0 +inf ?inf qnan snan fcnvsd(fpul frn) +norm ?norm +0 ?0 +inf ?inf qnan invalid note: the value of a denormalized number is treated as 0. possible exceptions: ? invalid operation
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 289 of 484 rej09b0051-0300 6.5.6 fdiv floating-point divide floating-point instruction floating-point division pr format abstract code cycle t bit 0 fdiv frm,frn frn/frm frn 1111nnnnmmmm0011 10 ? 1 fdiv drm,drn drn/drm drn 1111nnn0mmm00011 23 ? description when fpscr.pr = 0: arithmetically divides the single-precision floating-point number in frn by the single-precision floating-point number in frm, and stores the result in frn. when fpscr.pr = 1: arithmetically divides the double-precision floating-point number in drn by the double-precision floating-point number in drm, and stores the result in drn. when fpscr.enable.o/u/i is set, an fpu exception trap is generated regardless of whether or not an exception has occurred. when an exception occurs, correct exception information is reflected in fpscr.cause and fpscr.flag, and frn or drn is not updated. appropriate processing should therefore be performed by software. operation void fdiv(int m,n) /* fdiv frm,frn */ { pc += 2; clear_cause(); if((data_type_of(m) == snan) || (data_type_of(n) == snan)) invalid(n); else if((data_type_of(m) == qnan) || (data_type_of(n) == qnan)) qnan(n); else switch (data_type_of(m)){ case norm: switch (data_type_of(n)){ case pinf: case ninf: inf(n,sign_of(m)^sign_of(n));break; case pzero: case nzero: zero(n,sign_of(m)^sign_of(n));break; default: normal_fdiv(m,n); break;
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 290 of 484 rej09b0051-0300 } break; case pzero: switch (data_type_of(n)){ case pzero: case nzero: invalid(n);break; case pinf: case ninf: break; default: dz(n,sign_of(m)^sign_of(n));break; } break; case nzero: switch (data_type_of(n)){ case pzero: case nzero: invalid(n); break; case pinf: inf(n,1); break; case ninf: inf(n,0); break; default: dz(fr[n],sign_of(m)^sign_of(n)); break; } break; case pinf : case ninf : switch (data_type_of(n)){ case pinf: case ninf: invalid(n); break; default: zero(n,sign_of(m)^sign_of(n));break } break; } } void normal_fdiv(int m,n) { union { float f; int l; } dstf,tmpf; union { double d; int l[2]; } dstd,tmpd; union { int double x;
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 291 of 484 rej09b0051-0300 int l[4]; } tmpx; if(fpscr_pr == 0) { tmpf.f = fr[n]; /* save destination value */ dstf.f /= fr[m]; /* round toward nearest or even */ tmpd.d = dstf.f; /* convert single to double */ tmpd.d *= fr[m]; if(tmpf.f != tmpd.d) set_i(); if((tmpf.f < tmpd.d) && (spscr_rm == 1)) dstf.l -= 1; /* round toward zero */ check_single_exception(&fr[n], dstf.f); } else { tmpd.d = dr[n>>1]; /* save destination value */ dstd.d /= dr[m>>1]; /* round toward nearest or even */ tmpx.x = dstd.d; /* convert double to int double */ tmpx.x *= dr[m>>1]; if(tmpd.d != tmpx.x) set_i(); if((tmpd.d < tmpx.x) && (spscr_rm == 1)) { dstd.l[1] -= 1; /* round toward zero */ if(dstd.l[1] == 0xffffffff) dstd.l[0] -= 1; } check_double_exception(&dr[n>>1], dstd.d); } }
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 292 of 484 rej09b0051-0300 fdiv special cases frm,drm frn,drn norm +0 ?0 +inf ?inf qnan snan norm div 0 inf +0 dz invalid +inf ?inf ?0 ?inf +inf +inf 0 +0 ?0 invalid ?inf ?0 +0 qnan qnan snan invalid note: the value of a denormalized number is treated as 0. possible exceptions: ? invalid operation ? divide by zero ? overflow ? underflow ? inexact
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 293 of 484 rej09b0051-0300 6.5.7 fldi0 floating-point load immediate 0.0 floating-point instruction 0.0 load pr format abstract code cycle t bit 0 fldi0 frn 0x00000000 frn 1111nnnn10001101 1? 1? ? ? ? ? description when fpscr.pr = 0, this instruction loads floating-point 0.0 (0x00000000) into frn. if fpscr.pr = 1, the instruction is handled as an illegal instruction. operation void fldi0(int n) { fr[n] = 0x00000000; pc += 2; } possible exceptions: none
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 294 of 484 rej09b0051-0300 6.5.8 fldi1 floating-point load immediate 1.0 floating-point instruction 1.0 load format abstract code cycle t bit fldi1 frn 0x3f800000 frn 1111nnnn10011101 1? ?? ??? description when fpscr.pr = 0, this instruction loads floating-point 1.0 (0x3f800000) into frn. if fpcsr.pr = 1, the instruction is handled as an illegal instruction. operation void fldi1(int n) { fr[n] = 0x3f800000; pc += 2; } possible exceptions: none
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 295 of 484 rej09b0051-0300 6.5.9 flds floating-point load to system register floating-point instruction transfer to system register format abstract code cycle t bit flds frm,fpul frm fpul 1111mmmm00011101 1? description this instruction loads the contents of floating-point register frm into system register fpul. operation void flds(int m, float *fpul) { *fpul = fr[m]; pc += 2; } possible exceptions: none
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 296 of 484 rej09b0051-0300 6.5.10 float floating-point convert from integer floating-point instruction integer to floating-point conversion pr format abstract code cycle t bit 0 float fpul,frn (float)fpul frn 1111nnnn00101101 1? 1 float fpul,drn (double)fpul drn 1111nnn000101101 2? description when fpscr.pr = 0: taking the contents of fpul as a 32-bit integer, converts this integer to a single-precision floating-point number and stores the result in frn. when fpscr.pr = 1: taking the contents of fpul as a 32-bit integer, converts this integer to a double-precision floating-point number and stores the result in drn. when fpscr.enable.i = 1, and fpscr.pr = 0, an fpu exception trap is generated regardless of whether or not an exception has occurred. when an exception occurs, correct exception information is reflected in fpscr.cause and fpscr.flag, and frn or drn is not updated. appropriate processing should therefore be performed by software.
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 297 of 484 rej09b0051-0300 operation void float(int n, float *fpul) { union { double d; int l[2]; } tmp; pc += 2; clear_cause(); if(fpscr.pr==0){ fr[n] = *fpul; /* convert from integer to float */ tmp.d = *fpul; if(tmp.l[1] & 0x1fffffff) inexact(); } else { dr[n>>1] = *fpul; /* convert from integer to double */ } } possible exceptions: inexact: not generated when fpscr.pr = 1.
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 298 of 484 rej09b0051-0300 6.5.11 fmac floating-point multiply and accumulate floating-point instruction floating-point multiply and accumulate pr format abstract code cycle t bit 0 fmac fr0,frm,frn fr0*frm+frn frn 1111nnnnmmmm1110 1? 1? ? ? ? ? description when fpscr.pr = 0, this instruction arithmetically multiplies the two single-precision floating- point numbers in fr0 and frm, arithmetically adds the contents of frn, and stores the result in frn. when fpscr.enable.o/u/i is set, an fpu exception trap is generated regardless of whether or not an exception has occurred. when an exception occurs, correct exception information is reflected in fpscr.cause and fpscr.flag, and frn is not updated. appropriate processing should therefore be performed by software. if fpscr.pr = 1, the instruction is handled as an illegal instruction. operation void fmac(int m,n) { pc += 2; clear_cause(); if(fpscr_pr == 1) undefined_operation(); else if((data_type_of(0) == snan) || (data_type_of(m) == snan) || (data_type_of(n) == snan)) invalid(n); else if((data_type_of(0) == qnan) || (data_type_of(m) == qnan)) qnan(n); else if((data_type_of(0) == denorm) || (data_type_of(m) == denorm)) set_e(); else switch (data_type_of(0){ case norm: switch (data_type_of(m)){
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 299 of 484 rej09b0051-0300 case pzero: case nzero: switch (data_type_of(n)){ case qnan: qnan(n); break; case pzero: case nzero: zero(n,sign_of(0)^ sign_of(m)^sign_of(n)); break; default: break; } case pinf: case ninf: switch (data_type_of(n)){ case qnan: qnan(n); break; case pinf: case ninf: if(sign_of(0)^ sign_of(m)^sign_of(n)) invalid(n); else inf(n,sign_of(0)^ sign_of(m)); break; default: inf(n,sign_of(0)^ sign_of(m)); break; } case norm: switch (data_type_of(n)){ case qnan: qnan(n); break; case pinf: case ninf: inf(n,sign_of(n)); break; case pzero: case nzero: case norm: normal_fmac(m,n); break; } break; case pzero: case nzero: switch (data_type_of(m)){ case pinf: case ninf: invalid(n); break; case pzero: case nzero: case norm: switch (data_type_of(n)){ case qnan: qnan(n); break; case pzero: case nzero: zero(n,sign_of(0)^ sign_of(m)^sign_of(n)); break; default: break;
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 300 of 484 rej09b0051-0300 } break; } break; case pinf : case ninf : switch (data_type_of(m)){ case pzero: case nzero: invalid(n); break; default: switch (data_type_of(n)){ case qnan: qnan(n); break; default: inf(n,sign_of(0)^sign_of(m)^sign_of(n));break } break; } break; } } void normal_fmac(int m,n) { union { int double x; int l[4]; } dstx,tmpx; float dstf,srcf; if((data_type_of(n) == pzero)|| (data_type_of(n) == nzero)) srcf = 0.0; /* flush denormalized value */ else srcf = fr[n]; tmpx.x = fr[0]; /* convert single to int double */ tmpx.x *= fr[m]; /* exact product */ dstx.x = tmpx.x + srcf; if(((dstx.x == srcf) && (tmpx.x != 0.0)) || ((dstx.x == tmpx.x) && (srcf != 0.0))) { set_i(); if(sign_of(0)^ sign_of(m)^ sign_of(n)) { dstx.l[3] -= 1; /* correct result */ if(dstx.l[3] == 0xffffffff) dstx.l[2] -= 1; if(dstx.l[2] == 0xffffffff) dstx.l[1] -= 1; if(dstx.l[1] == 0xffffffff) dstx.l[0] -= 1; }
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 301 of 484 rej09b0051-0300 else dstx.l[3] |= 1; } if((dstx.l[1] & 0x01ffffff) || dstx.l[2] || dstx.l[3]) set_i(); if(fpscr_rm == 1) { dstx.l[1] &= 0xfe000000; /* round toward zero */ dstx.l[2] = 0x00000000; dstx.l[3] = 0x00000000; } dstf = dstx.x; check_single_exception(&fr[n],dstf); }
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 302 of 484 rej09b0051-0300 fmac special cases frn fr0 frm +norm ?norm +0 ?0 +inf ?inf qnan snan norm norm mac inf 0 invalid inf inf invalid inf +0 norm mac 0 +0 invalid inf inf invalid inf ?0 +norm mac +0 ?0 +inf ?inf ?norm ?0 +0 ?inf +inf +0 +0 ?0 +0 ?0 invalid ?0 ?0 +0 ?0 +0 inf inf invalid inf +inf +norm +inf invalid ?norm +inf 0 invalid +inf invalid +inf ?inf invalid +inf +inf ?inf +norm ?inf ?inf ?norm 0 +inf invalid invalid ?inf ?inf ?inf ?inf invalid qnan 0 invalid inf invalid norm !snan qnan qnan all types snan snan all types invalid note: when dn = 1, the value of a denormalized number is treated as 0.
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 303 of 484 rej09b0051-0300 possible exceptions: ? invalid operation ? overflow ? underflow ? inexact
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 304 of 484 rej09b0051-0300 6.5.12 fmov floating-point move floating-point instruction floating-point transfer no. sz format abstract code cycle t bit 1. 0 fmov frm,frn frm frn 1111nnnnmmmm1100 1? 2. 1 fmov drm,drn drm drn 1111nnn0mmm01100 2? 3. 0 fmov.s frm,@rn frm (rn) 1111nnnnmmmm1010 1? 4. 1 fmov.d drm,@rn drm (rn) 1111nnnnmmm01010 2? 5. 0 fmov.s @rm,frn (rm) frn 1111nnnnmmmm1000 1? 6. 1 fmov.d @rm,drn (rm) drn 1111nnn0mmmm1000 2? 7. 0 fmov.s @rm+,frn (rm) frn,rm+=4 1111nnnnmmmm1001 1? 8. 1 fmov.d @rm+,drn (rm) drn,rm+=8 1111nnn0mmmm1001 2? 9. 0 fmov.s frm,@-rn rn-=4,frm (rn) 1111nnnnmmmm1011 1? 10. 1 fmov.d drm,@-rn rn-=8,drm (rn) 1111nnnnmmm01011 2? 11. 0 fmov.s @(r0,rm),frn (r0+rm) frn 1111nnnnmmmm0110 1? 12. 1 fmov.d @(r0,rm),drn (r0+rm) drn 1111nnn0mmmm0110 2? 13. 0 fmov.s frm, @(r0,rn) frm (r0+rn) 1111nnnnmmmm0111 1? 14. 1 fmov.d drm, @(r0,rn) drm (r0+rn) 1111nnnnmmm00111 2? description 1. this instruction transfers frm contents to frn. 2. this instruction transfers drm contents to drn. 3. this instruction transfers frm contents to memory at address indicated by rn. 4. this instruction transfers drm contents to memory at address indicated by rn. 5. this instruction transfers contents of memory at address indicated by rm to frn. 6. this instruction transfers contents of memory at address indicated by rm to drn. 7. this instruction transfers contents of memory at address indicated by rm to frn, and adds 4 to rm. 8. this instruction transfers contents of memory at address indicated by rm to drn, and adds 8 to rm. 9. this instruction subtracts 4 from rn, and transfers frm contents to memory at address indicated by resulting rn value. 10. this instruction subtracts 8 from rn, and transfers drm contents to memory at address indicated by resulting rn value.
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 305 of 484 rej09b0051-0300 11. this instruction transfers contents of memory at address indicated by (r0 + rm) to frn. 12. this instruction transfers contents of memory at address indicated by (r0 + rm) to drn. 13. this instruction transfers frm contents to memory at address indicated by (r0 + rn). 14. this instruction transfers drm contents to memory at address indicated by (r0 + rn). operation void fmov(int m,n) /* fmov frm,frn */ { fr[n] = fr[m]; pc += 2; } void fmov_dr(int m,n) /* fmov drm,drn */ { dr[n>>1] = dr[m>>1]; pc += 2; } void fmov_store(int m,n) /* fmov.s frm,@rn */ { store_int(fr[m],r[n]); pc += 2; } void fmov_store_dr(int m,n) /* fmov.d drm,@rn */ { store_quad(dr[m>>1],r[n]); pc += 2; } void fmov_load(int m,n) /* fmov.s @rm,frn */ { load_int(r[m],fr[n]); pc += 2; } void fmov_load_dr(int m,n) /* fmov.d @rm,drn */ { load_quad(r[m],dr[n>>1]); pc += 2;
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 306 of 484 rej09b0051-0300 } void fmov_restore(int m,n) /* fmov.s @rm+,frn */ { load_int(r[m],fr[n]); r[m] += 4; pc += 2; } void fmov_restore_dr(int m,n) /* fmov.d @rm+,drn */ { load_quad(r[m],dr[n>>1]) ; r[m] += 8; pc += 2; } void fmov_save(int m,n) /* fmov.s frm,@?rn */ { store_int(fr[m],r[n]-4); r[n] -= 4; pc += 2; } void fmov_save_dr(int m,n) /* fmov.d drm,@?rn */ { store_quad(dr[m>>1],r[n]-8); r[n] -= 8; pc += 2; } void fmov_index_load(int m,n) /* fmov.s @(r0,rm),frn */ { load_int(r[0] + r[m],fr[n]); pc += 2; } void fmov_index_load_dr(int m,n) /*fmov.d @(r0,rm),drn */ { load_quad(r[0] + r[m],dr[n>>1]); pc += 2; }
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 307 of 484 rej09b0051-0300 void fmov_index_store(int m,n) /*fmov.s frm,@(r0,rn)*/ { store_int(fr[m], r[0] + r[n]); pc += 2; } void fmov_index_store_dr(int m,n)/*fmov.d drm,@(r0,rn)*/ { store_quad(dr[m>>1], r[0] + r[n]); pc += 2; } possible exceptions: ? address error
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 308 of 484 rej09b0051-0300 6.5.13 fmul floating-point multiply floating-point instruction floating-point multiplication pr format abstract code cycle t bit 0 fmul frm,frn frn*frm frn 1111nnnnmmmm0010 1? 1 fmul drm,drn drn*drm drn 1111nnn0mmm00010 6? description when fpscr.pr = 0: arithmetically multiplies the two single-precision floating-point numbers in frn and frm, and stores the result in frn. when fpscr.pr = 1: arithmetically multiplies the two double-precision floating-point numbers in drn and drm, and stores the result in drn. when fpscr.enable.o/u/i is set, an fpu exception trap is generated regardless of whether or not an exception has occurred. when an exception occurs, correct exception information is reflected in fpscr.cause and fpscr.flag, and frn or drn is not updated. appropriate processing should therefore be performed by software. operation void fmul(int m,n) { pc += 2; clear_cause(); if((data_type_of(m) == snan) || (data_type_of(n) == snan)) invalid(n); else if((data_type_of(m) == qnan) || (data_type_of(n) == qnan)) qnan(n); else switch (data_type_of(m){ case norm: switch (data_type_of(n)){ case pzero: case nzero: zero(n,sign_of(m)^sign_of(n)); break; case pinf: case ninf: inf(n,sign_of(m)^sign_of(n)); break; default: normal_fmul(m,n); break;
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 309 of 484 rej09b0051-0300 } break; case pzero: case nzero: switch (data_type_of(n)){ case pinf: case ninf: invalid(n); break; default: zero(n,sign_of(m)^sign_of(n));break; } break; case pinf : case ninf : switch (data_type_of(n)){ case pzero: case nzero: invalid(n); break; default: inf(n,sign_of(m)^sign_of(n));break } break; } } fmul special cases frm,drm frn,drn norm +0 ?0 +inf ?inf qnan snan norm mul 0 inf +0 0 +0 ?0 invalid ?0 ?0 +0 +inf inf invalid +inf ?inf ?inf ?inf +inf qnan qnan snan invalid note: the value of a denormalized number is treated as 0. possible exceptions: ? invalid operation ? overflow ? underflow ? inexact
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 310 of 484 rej09b0051-0300 6.5.14 fneg floating-point negate value floating-point instruction floating-point sign inversion pr format abstract code cycle t bit 0 fneg frn -frn frn 1111nnnn01001101 1? 1 fneg drn -drn drn 1111nnn001001101 1? description this instruction inverts the most significant bit (sign bit) of the contents of floating-point register frn/drn, and stores the result in frn/drn. the cause and flag fields in fpscr are not updated. operation void fneg (int n){ fr[n] = -fr[n]; pc += 2; } /* same operation is performed regardless of precision. */ possible exceptions: none
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 311 of 484 rej09b0051-0300 6.5.15 fschg sz-bit change floating-point instruction sz bit inversion pr format abstract code cycle t bit 0 fschg fpscr.sz=~fpscr.sz 1111001111111101 1? 1? ? ? ? ? description when fpscr.pr = 0, this instruction inverts the sz bit in floating-point register fpscr. changing the sz bit in fpscr switches fmov instruction data transfer between one single- precision data unit and a data pair. when fpscr.sz = 0, the fmov instruction transfers one single-precision data unit. when fpscr.sz = 1, the fmov instruction transfers two single- precision data units as a pair. if fpscr.pr = 1, the instruction is handled as an illegal instruction. operation void fschg() /* fschg */ { if(fpscr_pr == 0){ fpscr ^= 0x00100000; /* bit 20 */ pc += 2; } else undefined_operation(); } possible exceptions: none
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 312 of 484 rej09b0051-0300 6.5.16 fsqrt floating-point square root floating-point instruction floating-point square root pr format abstract code cycle t bit 0fsqrtfrn frn frn 1111nnnn01101101 9? 1 fsqrt drn drn drn 1111nnnn01101101 22 ? description when fpscr.pr = 0: finds the arithmetical square root of the single-precision floating-point number in frn, and stores the result in frn. when fpscr.pr = 1: finds the arithmetical square root of the double-precision floating-point number in drn, and stores the result in drn. when fpscr.enable.i is set, an fpu exception trap is generated regardless of whether or not an exception has occurred. when an exception occurs, correct exception information is reflected in fpscr.cause and fpscr.flag, and frn or drn is not updated. appropriate processing should therefore be performed by software. operation void fsqrt(int n){ pc += 2; clear_cause(); switch(data_type_of(n)){ case norm : if(sign_of(n) == 0) normal_ fsqrt(n); else invalid(n); break; case pzero : case nzero : case pinf : break; case ninf : invalid(n); break; case qnan : qnan(n); break; case snan : invalid(n); break; } }
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 313 of 484 rej09b0051-0300 void normal_fsqrt(int n) { union { float f; int l; } dstf,tmpf; union { double d; int l[2]; } dstd,tmpd; union { int double x; int l[4]; } tmpx; if(fpscr_pr == 0) { tmpf.f = fr[n]; /* save destination value */ dstf.f = sqrt(fr[n]); /* round toward nearest or even */ tmpd.d = dstf.f; /* convert single to double */ tmpd.d *= dstf.f; if(tmpf.f != tmpd.d) set_i(); if((tmpf.f < tmpd.d) && (spscr_rm == 1)) dstf.l -= 1; /* round toward zero */ if(fpscr & enable_i) fpu_exception_trap(); else fr[n] = dstf.f; } else { tmpd.d = dr[n>>1]; /* save destination value */ dstd.d = sqrt(dr[n>>1]); /* round toward nearest or even */ tmpx.x = dstd.d; /* convert double to int double */ tmpx.x *= dstd.d; if(tmpd.d != tmpx.x) set_i(); if((tmpd.d < tmpx.x) && (spscr_rm == 1)) { dstd.l[1] -= 1; /* round toward zero */ if(dstd.l[1] == 0xffffffff) dstd.l[0] -= 1; }
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 314 of 484 rej09b0051-0300 if(fpscr & enable_i) fpu_exception_trap(); else dr[n>>1] = dstd.d; } } fsqrt special cases frn +norm ?norm +0 ?0 +inf ?inf qnan snan fsqrt(frn) sqrt invalid +0 ?0 +inf invalid qnan invalid note: the value of a denormalized number is treated as 0. possible exceptions: ? invalid operation ? inexact
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 315 of 484 rej09b0051-0300 6.5.17 fsts floating-point store system register floating-point instruction transfer from system register format abstract code cycle t bit fsts fpul,frn fpul frn 1111nnnn00001101 1? description this instruction transfers the contents of system register fpul to floating-point register frn. operation void fsts(int n, float *fpul) { fr[n] = *fpul; pc += 2; } possible exceptions: none
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 316 of 484 rej09b0051-0300 6.5.18 fsub floating-point subtract floating-point instruction floating-point subtraction pr format abstract code cycle t bit 0 fsub frm,frn frn-frm frn 1111nnnnmmmm0001 1? 1 fsub drm,drn drn-drm drn 1111nnn0mmm00001 6 description when fpscr.pr = 0: arithmetically subtracts the single-precision floating-point number in frm from the single-precision floating-point number in frn, and stores the result in frn. when fpscr.pr = 1: arithmetically subtracts the double-precision floating-point number in drm from the double-precision floating-point number in drn, and stores the result in drn. when fpscr.enable.o/u/i is set, an fpu exception trap is generated regardless of whether or not an exception has occurred. when an exception occurs, correct exception information is reflected in fpscr.cause and fpscr.flag, and frn or drn is not updated. appropriate processing should therefore be performed by software. operation void fsub (int m,n) { pc += 2; clear_cause(); if((data_type_of(m) == snan) || (data_type_of(n) == snan)) invalid(n); else if((data_type_of(m) == qnan) || (data_type_of(n) == qnan)) qnan(n); else switch (data_type_of(m)){ case norm: switch (data_type_of(n)){ case norm: normal_faddsub(m,n,sub); break; case pzero: case nzero: register_copy(m,n); fr[n] = -fr[n];break; default: break;
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 317 of 484 rej09b0051-0300 } break; case pzero: break; case nzero: switch (data_type_of(n)){ case nzero: zero(n,0); break; default: break; } break; case pinf: switch (data_type_of(n)){ case pinf: invalid(n); break; default: inf(n,1); break; } break; case ninf: switch (data_type_of(n)){ case ninf: invalid(n); break; default: inf(n,0); break; } break; } } fsub special cases frm,drm frn,drn norm +0 ?0 +inf ?inf qnan snan norm sub +inf ?inf +0 ?0 ?0 +0 +inf ?inf invalid ?inf +inf invalid qnan qnan snan invalid note: the value of a denormalized number is treated as 0. possible exceptions: ? invalid operation ? overflow ? underflow ? inexact
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 318 of 484 rej09b0051-0300 6.5.19 ftrc floating-point truncate and convert to integer floating-point instruction conversion to integer pr format abstract code cycle t bit 0 ftrc frm,fpul (long)frm fpul 1111mmmm00111101 1? 1 ftrc drm,fpul (long)drm fpul 1111mmm000111101 2? description when fpscr.pr = 0: converts the single-precision floating-point number in frm to a 32-bit integer, and stores the result in fpul. when fpscr.pr = 1: converts the double-precision floating-point number in frm to a 32-bit integer, and stores the result in fpul. the rounding mode is always truncation. operation #define n_int_single_range 0xcf000000 & 0x7fffffff /* -1.000000 * 2^31 */ #define p_int_single_range 0x4effffff /* 1.fffffe * 2^30 */ #define n_int_double_range 0xc1e0000000200000 & 0x7fffffffffffffff #define p_int_double_range 0x41e0000000000000 void ftrc(int m, int *fpul) { pc += 2; clear_cause(); if(fpscr.pr==0){ case(ftrc_single_ type_of(m)){ norm: *fpul = fr[m]; break; pinf: ftrc_invalid(0); break; ninf: ftrc_invalid(1); break; } } else{ /* case fpscr.pr=1 */
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 319 of 484 rej09b0051-0300 case(ftrc_double_type_of(m)){ norm: *fpul = dr[m>>1]; break; pinf: ftrc_invalid(0); break; ninf: ftrc_invalid(1); break; } } } int ftrc_signle_type_of(int m) { if(sign_of(m) == 0){ if(fr_hex[m] > 0x7f800000) return(ninf); /* nan */ else if(fr_hex[m] > p_int_single_range) return(pinf); /* out of range,+inf */ else return(norm); /* +0,+norm */ } else { if((fr_hex[m] & 0x7fffffff) > n_int_single_range) return(ninf); /* out of range ,+inf,nan*/ else return(norm); /* -0,-norm */ } } int ftrc_double_type_of(int m) { if(sign_of(m) == 0){ if((fr_hex[m] > 0x7ff00000) || ((fr_hex[m] == 0x7ff00000) && (fr_hex[m+1] != 0x00000000))) return(ninf); /* nan */ else if(dr_hex[m>>1] >= p_int_double_range) return(pinf); /* out of range,+inf */ else return(norm); /* +0,+norm */ } else { if((dr_hex[m>>1] & 0x7fffffffffffffff) >= n_int_double_range) return(ninf); /* out of range ,+inf,nan*/ else return(norm); /* -0,-norm */ } }
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 320 of 484 rej09b0051-0300 void ftrc_invalid(int sign, int *fpul) { set_v(); if((fpscr & enable_v) == 0){ if(sign == 0) *fpul = 0x7fffffff; else *fpul = 0x80000000; } else fpu_exception_trap(); } ftrc special cases frn,drn norm +0 ?0 positive out of range negative out of range +inf ?inf qnan snan ftrc (frn,drn) trc 0 0 invalid +max invalid ?max invalid +max invalid ?max invalid ?max invalid ?max note: the value of a denormalized number is treated as 0. possible exceptions: ? invalid operation
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 321 of 484 rej09b0051-0300 6.5.20 lds load to fpu system register system control instruction load to fpu system register format abstract code cycle t bit lds rm,fpul rm fpul 0100mmmm01011010 1? lds.l @rm+,fpul (rm) fpul, rm+4 rm 0100mmmm01010110 1? lds rm,fpscr rm fpscr 0100mmmm01101010 1? lds.l @rm+,fpscr (rm) fpscr, rm+4 rm 0100mmmm01100110 1? description this instruction loads the source operand into fpu system registers fpul and fpscr. operation #define fpscr_mask 0x003fffff ldsfpul(int m, int *fpul) /* lds rm,fpul */ { *fpul=r[m]; pc+=2; } ldsmfpul(int m, int *fpul) /* lds.l @rm+,fpul */ { *fpul=read_long(r[m]); r[m]+=4; pc+=2; } ldsfpscr(int m) /* lds rm,fpscr */ { fpscr=r[m] & fpscr_mask; pc+=2; } ldsmfpscr(int m) /* lds.l @rm+,fpscr */ {
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 322 of 484 rej09b0051-0300 fpscr=read_long(r[m]) & fpscr_mask; r[m]+=4; pc+=2; } possible exceptions: ? address error
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 323 of 484 rej09b0051-0300 6.5.21 sts store from fpu system register system control instruction store from fpu system register format abstract code cycle t bit sts fpul,rn fpul rn 0000nnnn01011010 1? sts fpscr,rn fpscr rn 0000nnnn01101010 1? sts.l fpul,@-rn rn-4 rn, fpul (rn) 0100nnnn01010010 1? sts.l fpscr,@-rn rn-4 rn, fpscr (rn) 0100nnnn01100010 1? description this instruction stores fpu system register fpul or fpscr in the destination. operation sts(int n, int *fpul) /* sts fpul,rn */ { r[n]= *fpul; pc+=2; } sts_save(int n, int *fpul) /* sts.l fpul,@-rn */ { r[n]-=4; write_long(r[n],*fpul) ; pc+=2; } sts(int n) /* sts fpscr,rn */ { r[n]=fpscr&0x003fffff; pc+=2; } sts_restore(int n) /* sts.l fpscr,@-rn */ { r[n]-=4; write_long(r[n],fpscr&0x003fffff)
section 6 instruction descriptions rev. 3.00 jul 08, 2005 page 324 of 484 rej09b0051-0300 pc+=2; } possible exceptions: ? address error examples ? sts example 1: mov.l #h'12abcdef, r12 lds r12, fpul sts fpul, r13 ; after executing the sts instruction: ; r13 = 12abcdef example 2: sts fpscr, r2 ; after executing the sts instruction: ; the current content of fpscr is stored in register r2 ? sts.l example 1: mov.l #h'0c700148, r7 sts.l fpul, @-r7 ; before executing the sts.l instruction: ; r7 = 0c700148 ; after executing the sts.l instruction: ; r7 = 0c700144, and the content of fpul is saved at memory ; location 0c700144. example 2: mov.l #h'0c700154, r8 sts.l fpscr, @-r8 ; after executing the sts.l instruction: ; the content of fpscr is saved at memory location 0c700150.
section 7 register banks rev. 3.00 jul 08, 2005 page 325 of 484 rej09b0051-0300 section 7 register banks 7.1 overview the SH-2A/sh2a-fpu has on-chip register banks to provide high-speed register save and retrieve performance during interrupt processing. the configuration of the register banks is shown in figure 7.1. r0 general registers r1 r14 r15 sr gbr vbr tbr mach macl pr pc control registers ibcr bank control register bank control registers (interrupt controller) ibnr bank number register system registers .... r0 r1 r14 gbr mach macl pr vto .... register banks registers bank 0 bank 1 bank n - 1 interrupt generated (save) resbank instruction (retrieve) vto : interrupt vector table address offset : banked register notes: ..... figure 7.1 overview of register bank configuration
section 7 register banks rev. 3.00 jul 08, 2005 page 326 of 484 rej09b0051-0300 7.2 register banks and bank control registers 7.2.1 banked data the contents of general registers r0 to r14, the global register (gbr), the multiply and accumulate registers (mach, macl), the procedure register (pr), and the interrupt vector table address offsets (vto) are banked. 7.2.2 register banks the number of register banks is n, numbered from bank 0 to bank n ? 1 (maximum 512 banks). register banks are stacked in first in last out (filo) sequence. saves take place in order, beginning from bank 0, and retrieves take place in the reverse order, beginning from the last bank saved to. the number of banks, n, differs depending on the product. for details, refer to the register banks section of the hardware manual for the product in question. 7.2.3 bank control registers (1) bank control register (ibcr) (16 bit, initial value: h'0000) this register is used to allow or prohibit the use of specific register banks, based on the interrupt priority level or the interrupt source. the register specifications and initial values differ depending on the product. for details, refer to the interrupt controller section of the hardware manual for the product in question. bit 151413121110 9 8 7 6 5 4 3 2 1 0 e15 e14 e13 e12 e11 e10 e9 e8 e7 e6 e5 e4 e3 e2 e1 ? bits 15 to 1: e15 to e1 the setting of these bits is used to allow or prohibit use of register banks based on interrupt priority level (15 to 1). bits 15 to 1 e15 to e1 description 0 register bank use is prohibited. 1 register bank use is allowed. bit 0: reserved bit this bit is always read as 0 and only a value of 0 should be written to it.
section 7 register banks rev. 3.00 jul 08, 2005 page 327 of 484 rej09b0051-0300 (2) bank number register (ibnr) (16 bit, initial value: h'0000) bit 151413121110 9 8 7 6 5 4 3 2 1 0 be1 be0 bove ? ? ? ? ? ? ? ? ? bn3 bn2 bn1 bn0 the setting of the bank number register (ibnr) is used to allow or prohibit use of register banks and to allow or prohibit register bank overflow exceptions. in addition, bits bn3 to bn0 indicate the number of the next bank to be saved to. they are initialized to h'0000 by a power-on reset. bits 15 and 14: be1, be0 these bits specify whether register bank use is prohibited or allowed. bits 15, 14 be1, be0 description 00 use of the bank is prohibited for all interrupts. the setting of ibcr is ignored. (initial value) 01 use of the bank is prohibited for all interrupts except nmi and ubc. the setting of ibcr is ignored. 10 reserved. (do not attempt to set this bit.) 11 use of the bank is as specified by ibcr. bit 13: bove this bit specify whether register bank overflow exceptions are prohibited or allowed. bit 13 bove description 0 generation of register bank overflow exceptions is prohibited. (initial value) 1 generation of register bank overflow exceptions is allowed. bits 12 to 4: reserved bits these bits are always read as 0 and only a value of 0 should be written to them. bits 3 to 0: bn3 to bn0 these bits indicate the number of the next bank to be saved to. when an interrupt that uses a register bank is received, it is saved to the bank specified by bn3 to bn0 and bn is incremented by 1. execution of a register bank retrieve instruction causes bn to be decremented by 1, after which the data is retrieved from the register bank. these bits are read-only and cannot be modified.
section 7 register banks rev. 3.00 jul 08, 2005 page 328 of 484 rej09b0051-0300 7.3 bank save and retrieve operations 7.3.1 save to bank figure 7.2 illustrates the register bank save operations. the following operations are performed when an interrupt for which register bank use is allowed by ibcr is received by the cpu. (a) assume that the ibnr bank number value, bn, is i before the interrupt is generated. (b) the contents of registers r0 to r14, gbr, mach, macl, pr, and the interrupt vector table address offset (vto) are saved to the bank indicated by the bn, bank i. (c) the bn value is incremented by 1. bank 1 bank i (a) (c) (b) bank i+1 bn +1 bank 0 gbr r0 to r14 mach macl pr vto .... bank n-1 .... register banks registers figure 7.2 bank save operations figure 7.3 illustrates the register bank save timing. saving to the bank takes place between the start of interrupt exception processing and the start of the fetch of the first instruction in the exception service routine.
section 7 register banks rev. 3.00 jul 08, 2005 page 329 of 484 rej09b0051-0300 fde f f de emmm 2+m1+m2+m3 2 m1 m2 m3 (1)vto,pr,gbr,macl (2)r12,r13,r14,mach (3)r8,r9,r10,r11 save to bank (4)r4,r5,r6,r7 (5)r0,r1,r2,r3 overrun fetch instruction (instruction replacing interrupt exception processing) external interrupt first instruction in interrupt service routine m1: vector address read m2: sr save (stack) m3: pc save (stack) figure 7.3 bank save timing 7.3.2 retrieve from bank the retrieve from bank instruction, resbank, is used to retrieve data stored in a bank. after retrieving the data from the bank with the resbank instruction at the end of the interrupt service routine, use the rte instruction to return from exception processing. 7.3.3 save and retrieve operations after saving to all banks if, after data has been saved to all of the register banks, an interrupt for which register bank use is allowed is received by the cpu, data is saved automatically to the stack instead of a register bank. this is possible by masking the register bank overflow exception using the interrupt controller. if a register bank overflow exception were generated it would not be possible to save to the stack. for details, refer to the interrupt controller section of the hardware manual for the product in question. the automatic save to and retrieve from stack operations are described below. (1) save to stack (a) when interrupt exception processing occurs, the status register (sr) and program counter (pc) are saved on the stack. (b) the contents of the banked registers (r0 to r14, gbr, mach, macl, and pr) are saved to the stack. the order in which the contents of these registers are saved is macl, mach, gbr, pr, r14, r13, ? r1, r0. (c) the register bank overflow bit in sr is set to 1. (d) the bank number (bn) bits in the bank number register (ibnr) remain set to the maximum value, n.
section 7 register banks rev. 3.00 jul 08, 2005 page 330 of 484 rej09b0051-0300 (2) retrieve from stack if the retrieve from bank instruction, resbank, is executed when the register bank overflow bit in sr is set to 1, the following operations occur. (a) the contents of the banked registers (r0 to r14, gbr, mach, macl, and pr) are retrieved from the stack. the order in which the contents of these registers are retrieved is r0, r1, ? r13, r14, pr, gbr, mach, macl. (b) the bank number (bn) bits in the bank number register (ibnr) remain set to the maximum value, n. 7.4 register bank data send instructions the ldbank and stbank instructions can be used to send user-defined register bank data to and from general register r0 for debugging purposes. 7.4.1 description of instructions (1) ldbank (load data from register bank to r0) format: ldbank @rm,r0 operation: sends 4 bytes of data from the register bank address indicated by rm to r0. (2) stbank (store data from r0 to register bank) format: stbank r0,@rn operation: sends the contents of r0 to the register bank address indicated by rn. 7.4.2 register bank addressing figure 7.4 illustrates the correlation between register bank send command address values (rm in the case of ldbank and rn in the case of stbank) and register bank entries. the bank number is specified by address bits 15 to 7 (bn), and the entry within the bank (r0 to r14, gbr, mach, macl, pr, vto) is specified by address bits 6 to 2 (en). address bits 31 to 16 and 1 to 0 should all be cleared to 0. if the value of these bits is not all 0 operation cannot be guaranteed in cases where a nonexistent bank is specified by address bits 15 to 7 or a nonexistent entry is specified by address bits 6 to 2.
section 7 register banks rev. 3.00 jul 08, 2005 page 331 of 484 rej09b0051-0300 r0 00000 bank 0 000000000 bank 1 000000001 bank 2 000000010 bank 3 000000011 bank n-2 111111110 bank n-1 111111111 .... r1 00001 r2 00010 r3 00011 r4 00100 r5 00101 r6 00110 r7 00111 r8 01000 r9 01001 r10 01010 r11 01011 r12 01100 r13 01101 r14 01110 vto 10000 pr 10001 gbr 10010 macl 10011 31 16 15 2 1 0 76 0 0 bn en 00 ......................... register bank send instruction address (rm, rn) register banks (overall) n = 512 00110 000000011 single register bank mach 01111 figure 7.4 register bank addressing
section 7 register banks rev. 3.00 jul 08, 2005 page 332 of 484 rej09b0051-0300 7.5 register bank exceptions there are two types of register bank exception (register bank error): register bank overflow and register bank underflow. 7.5.1 register bank error sources (1) register bank overflow this exception occurs if, after data has been saved to all of the register banks, an interrupt for which register bank use is allowed is received by the cpu, and the register bank overflow exception is not masked by the interrupt controller. in this case the bank number (bn) bits in the bank number register (ibnr) remain set to the maximum value, n, and no data is saved to the register bank. (2) register bank underflow this exception occurs if the resbank instruction is executed when no data has been saved to the register banks. in this case the values of r0 to r14, gbr, mach, macl, and pr do not change. in addition, the bank number (bn) bits in the bank number register (ibnr) remain set to 0. 7.5.2 register bank error exception processing if a register bank error is generated, register bank error exception processing begins. when this happens the cpu performs the following operations. 1. the contents of the status register (sr) are saved to the stack. 2. the value of the program counter (pc) is saved to the stack. the pc value that is saved when a register bank overflow occurs is the starting address of the next instruction after the last executed instruction. the pc value that is saved when a register bank underflow occurs is the starting address of the relevant resbank instruction. to prevent multiple interrupts from occurring when a bank overflow occurs, the level of the interrupt that caused the overflow is written to the interrupt mask bits (i3 to i0) of the status register (sr). 3. the exception service routine start address is extracted from the exception processing vector table corresponding to the register bank error, and the program is run beginning from that address.
section 7 register banks rev. 3.00 jul 08, 2005 page 333 of 484 rej09b0051-0300 7.6 sr register bank overflow bit (bo bit) the bo bit is modified when the contents of the sr register are retrieved by the rte instruction. the bo bit is not modified when a resbank instruction is executed. the bo bit is set to 1 if exception generation by the interrupt controller is not enabled in cases where a bank overflow occurs during an interrupt. if exception generation by the interrupt controller is enabled for cases when a bank overflow occurs during an interrupt, the bo bit is not modified. the bo bit is modified by the ldc rm.sr and ldc.l @rmt.sr instructions.
section 7 register banks rev. 3.00 jul 08, 2005 page 334 of 484 rej09b0051-0300
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 335 of 484 rej09b0051-0300 section 8 pipeline operation this section describes the pipeline operation of the various instructions. this is information for calculating the number of cpu instruction execution states (number of system clock cycles). the SH-2A/sh2a-fpu is a 2-ilp (2-instruction-level-parallelism) super-scalar pipelining microprocessor. instruction execution is pipelined, and two instructions can be executed in parallel. a harvard architecture is used, and there is no contention between memory accesses and instruction fetches. as an instruction fetch unit is provided, the cpu core does not stop during an instruction fetch. 8.1 basic pipeline configuration the SH-2A/sh2a-fpu has the following pipelines (see figure 8.1). ? integer pipelines 1 and 2: process integer operations. ? memory access pipeline: processes memory accesses and the loading of data to the fpu. ? multiplier pipeline: processes multiply instructions and the storing of data from the fpu. ? branch pipeline: processes branch instructions. ? shift pipeline: processes shift instructions. ? fpu load/store pipeline: processes fpu load/store instructions. ? fpu arithmetic operation pipeline: processes fpu arithmetic operations. ? fpu division/square root extraction pipeline: processes fpu division and square root extraction. all instructions are first processed by an integer pipeline. and are also passed to another pipeline if necessary. these pipelines can all operate independently of each other. therefore, if there is no contention, two instructions can always continue to be issued. instructions that perform memory access and instructions that load data from the cpu to the fpu use the memory access pipeline. multiply instructions and multiplication result register access instructions use the multiplier pipeline. in addition, inspections that store data from the fpu use the wb stage of the multiplier pipeline. branch instructions use the branch pipeline. shift instructions use the shift pipeline. instructions that perform fpu internal register moves or data exchange from the fpu to memory or the cpu use the fpu load/store pipeline.
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 336 of 484 rej09b0051-0300 instructions that perform fpu arithmetic operations use the fpu arithmetic operation pipeline. of the fpu arithmetic operations, fdiv and fsqrt use the fpu arithmetic operation pipeline and fpu division/square root extraction pipeline. see section 8.9, pipeline operations for each instruction, for details. the cpu pipeline stages are described in detail below. ? if: instruction fetch an instruction is fetched from memory in which the program is stored. ? id: instruction decoding the fetched instruction is decoded. ? ex: instruction execution a data operation or address calculation is performed in accordance with the result of decoding. ? ma: memory access a memory data access is performed. generated by an instruction accompanying a memory access or an instruction that performs data exchange between the cpu and fpu. ? mm: multiplier access a multiplier access is performed. generated by an instruction accompanying a memory access or an instruction that loads data from the cpu to the fpu. ? wb: write-back the result (data) accessed by a memory access or multiplier access is returned to the register. the fpu pipeline stages are described in detail below. cpu and fpu pipelines share the first- stage instruction fetch (if). ? df: fpu decoding the fetched instruction is decoded. ? e1: fpu execution stage 1 a floating-point operation is initialized. ? e2: fpu execution stage 2 the floating-point operation is executed.
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 337 of 484 rej09b0051-0300 ? sf: fpu store the floating-point operation is completed, and the result is written to an fpu register. ? ed: fpu division and square root calculation used only for fdiv and fsqrt. ? ex: fpu load/store stage 1 floating-point load/store instruction data preparation is performed. ? na: fpu load/store stage 2 floating-point load/store instruction data exchange is performed. the length of all stages after id and df is the same. only if may be extended due to a wait for data, but as the instruction fetch unit and pipelines operate independently, pipelining can be continued in this case, also, for instructions that have already been fetched. as shown in figure 8.2, instruction stages continue to flow together with instruction execution, forming a pipeline. the basic pipeline flow is shown in figure 8.1. the interval during which one stage is executed is called a slot, and is indicated by ? ? ?. each instruction has at least a 3-stage structure. the three stages if, id, and ex (integer pipeline) are present for each instruction. thereafter, instruction processing is performed with the necessary pipelines operating simultaneously.
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 338 of 484 rej09b0051-0300 if if id id ex ex ma wb e1 e2 sf preceding instruction succeeding instruction priority allocation (always allocated) normal allocation (allocated if free) integer pipeline 1 integer pipeline 2 fpu arithmetic operation pipeline memory access pipeline mm mm multiplier pipeline wb ex ed fpu division/square root extraction pipeline ex na sf fpu load/store pipeline df df cpu fpu ex ex branch pipeline shift pipeline figure 8.1 SH-2A/sh2a-fpu pipelines ??????? : slots instruction 1 if id ex ma wb instruction 2 if id ex instruction 3 if id ex ma wb instruction 4 if id ex instruction 5 if id ex instruction 6 if id ex ma wb ? ? ? ? time instruction stream figure 8.2 basic pipeline configuration
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 339 of 484 rej09b0051-0300 8.2 slots and pipeline flow the interval during which one stage is executed is called a slot. the following rules apply to a slot. (1) each stage of an instruction (if, id, ex, ma, wb, mm, e1, e2, df, ed, sf, na) is always executed in one slot. two or more stages are never executed in one slot (see figure 8.3). the ed stage operates without regard to a slot. x ?? ??????? : slots instruction 1 if id ex ma wb instruction 2 if id ex ma wb note: id and ex of instruction 1 are executed in one slot. figure 8.3 impossible pipeline flow (1) (2) the maximum number of different stages of different instructions set in one slot is two in the case of integer pipelines, and one in the case of other pipelines. simultaneous pipeline execution never exceeds this number (see figure 8.4). instruction 1 if id ex instruction 2 if id ex ma wb instruction 3 if id ex note: three id stages are executed in one slot. figure 8.4 impossible pipeline flow (2) (3) the number of states (number of system clock cycles) s required for execution of one slot is calculated using the following conditions. (a) s = (maximum number of states among stages of each instruction contained in one slot) that is to say, instructions that have other short stages are stalled by the longest stage. (b) the number of execution states of each stage is as follows: ? if: number of memory access clocks for instruction fetch (as a fetch buffer is provided and instruction fetches are performed beforehand, pipeline stalling only occurs when a fetched instruction must be decoded immediately.) ? id: always 1 state ? ex: always 1 state
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 340 of 484 rej09b0051-0300 ? ma: number of memory access clocks for data access ? wb: always 1 state ? mm: always 1 state ? df: always 1 state ? e1: always 1 state ? e2: always 1 state ? sf: always 1 state ? ed: always 1 state, but operates without regard to slots. ? na: always 1 state for example, figure 8.5 shows the pipeline flow when if (memory access for instruction fetch) of instructions 1 and 2 takes 2 cycles, ma (memory access for data access) of instruction 1 takes 3 cycles, and other stages take 1 cycle. ??? indicates stalling. for the sake of simplicity, this figure does not take super-scalar operation into consideration. ? ? ? ?? ? : slots (2) (1) (1) (3) (1) number of states instruction 1 if if id ex ma ma ma wb instruction 2 if if id ? ? ex note: if if requires more than one cycle, the slot is extended only if the instruction must be decoded immediately. figure 8.5 slots requiring a number of cycles
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 341 of 484 rej09b0051-0300 8.3 instruction execution and parallel execution capability the SH-2A/sh2a-fpu is a 2-ilp (2-instruction-level-parallelism) super-scalar pipelining microprocessor. when two instructions are in the id stage, two instructions can be executed simultaneously (see figure 8.6). add r2,r3 if id ex mov.l @r0,r1 if id ex ma wb add r4,r3 if id ex fadd fr1,fr2 if df e1 e2 sf figure 8.6 example of parallel execution however, parallel execution is not possible in the following cases: ? when resource contention occurs (described in 8.3.1) ? when waiting for the result of a previously issued instruction (described in 8.3.2) ? when register contention or flag contention occurs (described in 8.3.3) ? when a multi-cycle instruction is executed as a preceding instruction (described in 8.3.4) ? when a 32-bit instruction is executed as a preceding instruction (described in 8.3.5) ? in the case of an instruction that uses fpscr, an fpu instruction, or an fpu-related cpu instruction (described in 8.3.6) ? delayed unconditional branch instruction at which a branch occurs, and delay slot (described in 8.3.7) when if stages are completed for two instructions without the occurrence of such contention, the SH-2A/sh2a-fpu can perform parallel execution of the two instructions. the above cases are described in the following subsections. terms used in the descriptions are as follows: ? preceding instruction: earlier instruction in the same slot ? succeeding instruction: later instruction in the same slot ? previously issued instruction: generic term for an instruction that has already been issued
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 342 of 484 rej09b0051-0300 previously issued instruction if id ex previously issued instruction if id ex ma wb preceding instruction if id ex succeeding instruction if id e1 e2 sf note: box indicates reference slot. figure 8.7 definitions of preceding, succeeding, and previously issued instructions 8.3.1 details of resource contention as there is only one each of pipelines other than integer pipelines, if a preceding instruction and succeeding instruction attempt to use such a pipeline simultaneously, contention occurs and the succeeding instruction has to wait to be executed. cases in which contention occurs are as follows. (1) when the preceding instruction and succeeding instruction are both instructions accompanying a memory access (figure 8.8) alternatively, in the case of a combination of a cpu fpu data transfer instruction and memory write instruction (figure 8.8), or a combination with another fpu cpu data transfer instruction. in these cases, memory access pipeline contention occurs. mov.l @r1+,r2 if id ex ma mov.l @r1+,r3 if ? id ex ma note: there is a maximum of one memory access (ma) per slot. figure 8.8 example of memory access contention lds r0,fpul if id ex : cpu pipeline if df ex na sf : fpu pipeline mov.l r1,@r3 if ? id ex ma : cpu pipeline note: contention between lds instruction and memory write instruction figure 8.9 example of contention between lds instrunction and memory write instruction
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 343 of 484 rej09b0051-0300 instructions that transfer data from the fpu to the cpu do not conflict with memory access instructions (figure 8.10). in addition, instructions that transfer data from the cpu to the fpu do not conflict with memory access instructions (figure 8.11). sts fpul,r0 if id ex wb : cpu pipeline if df ex na sf : fpu pipeline mov.l r1,@r3 if id ex ma wb wb : cpu pipeline note: no contention between sts instruction and memory access instruction figure 8.10 example of contention between sts and memory access lds r0,fpul if id ex : cpu pipeline if df ex na sf : fpu pipeline mov.l @r1+,r3 if id ex ma wb : cpu pipeline note: no contention between lds instruction and memory read instruction figure 8.11 example of lds instruction and memory read instruction (2) when the preceding instruction and succeeding instruction are both instructions that use the multiplier (figure 8.12). with the multiplier, contention also occurs when a previously issued instruction is locked (figure 8.13). in addition, instructions that read mach or macl, mulr instructions, and instructions that transfer the value of fpul or fpscr to the cpu cause contention because they share the read bus (figure 8.14). muls.w r2,r1 if id mm mm mulr r0,r3 if ? id mm mm mm wb figure 8.12 example of multiplier contention multiplier locked ? lds.l @r1+, mach if id ex ma wb mulr r0,r3 if ? ? id mm mm mm wa figure 8.13 example of contention due to previously issued instruction
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 344 of 484 rej09b0051-0300 sts mach,r0 if id ex ma wb sts fpul,r1 if ? id mm mm mm wb note: the two instructions using the multiplication result read bus conflict with each other. figure 8.14 example of contention between instructions using multiplication result read bus (3) when the preceding instruction and succeeding instruction are both shift instructions or rotate instructions (figure 8.15) shad r0,r1 if id ex shad r2,r3 if ? id ex figure 8.15 example of shift instruction contention (4) when the preceding instruction and succeeding instruction are both fpu arithmetic operation instructions (figure 8.16) with regard to fpu arithmetic operation instructions, complex resource contention occurs with double-precision instructions or with fdiv or fsqrt instructions. see section 8.6, contention due to fpu, for details. fadd fr0,fr1 if df e1 e2 sf fadd fr2,fr3 if ? df e1 e2 sf figure 8.16 example of fpu arithmetic operation instruction contention (5) when the preceding instruction and succeeding instruction are both fpu load/store instructions (figure 8.17) fneg fr0 if df ex na sf fmov fr1,fr3 if ? df ex na sf figure 8.17 example of fpu load/store instruction contention
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 345 of 484 rej09b0051-0300 8.3.2 details of contention due to wait for result of previously issued instruction when the result of a previously issued instruction is used as a source, execution is performed after a wait equivalent to the latency of that instruction. cases where this applies include the following: ? when waiting for the result of a memory access (see section 8.5, effect of memory load instruction on pipeline, for details) ? when waiting for the result of an fpu operation (see section 8.6, contention due to fpu, for details) ? when waiting for the result of multiplication (see section 8.7, contention due to multiplier, for details) if the preceding instruction causes contention in these cases, the succeeding instruction must wait to be executed. if the succeeding instruction causes contention, the preceding instruction is executed if there is no other contention. 8.3.3 details of register contention and flag contention in the following cases, register contention or flag contention occurs in the same slot. (1) when the succeeding instruction uses the destination register or flag of the preceding instruction as a source register or flag (excluding a case where the preceding instruction is a zero-latency instruction) (figures 8.18 and 8.19) cmp/eq r2,r3 if id ex bf if ? id ex figure 8.18 example of flag contention between preceding destination and succeeding source mov r3,r4 if id ex add r4,r5 if id ex figure 8.19 example of no contention between zero-latency instruction and succeeding instruction
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 346 of 484 rej09b0051-0300 (2) when the succeeding instruction writes to the destination register or flag of the preceding instruction. (however, contention only occurs if an instruction other than a multiply instruction, divide instruction, ldbank instruction, resbank instruction, movmu instruction, or movml instruction writes to registers and flags other than the fpu register and cs bit. no contention is detected with a multiply instruction, divide instruction, ldbank instruction, or resbank instruction. in addition, contention is only detected for rn with the movmu instruction and for r0 with the movml instruction. no contention occurs if either of these instructions write to other registers.) (figures 8.20 to 8.25) add r3,r4 if id ex mov r5,r4 if ? id ex figure 8.20 example of contention due to instruction that overwrites destination of preceding instruction 1 mov.l @r0,r1 if id ex ma mov.l @r2,r1 if ? ? id ex figure 8.21 example of contention due to instruction that overwrites destination of preceding instruction 2 clips.b r3 if id ex clips.b r4 if id ex figure 8.22 example of no contention in case of cs bit mov r5,r6 if id ex mulr r0,r6 if id mmmmmmwb figure 8.23 example of mulr no contention mov r5,r6 if id ex movmu.l@r15+,r13 if id ex ma ma ma wb figure 8.24 example of movmu.l no contention
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 347 of 484 rej09b0051-0300 mov r5,r13 if id ex movmu.l@r15+,r13 if -- id ex ma ma ma wb figure 8.25 example of movmu.l contention 8.3.4 details of contention due to multi-cycle instruction an instruction that does not have one execution state is called a ?multi-cycle instruction.? the following rules apply to such instructions. (1) when a multi-cycle instruction is executed as a preceding instruction, it cannot be executed in parallel with the succeeding instruction. (2) during execution of a multi-cycle instruction, if the slot is not the last slot, the next instruction cannot be newly executed. ?during execution? here refers to a slot not exceeding the number of execution state cycles counting from the instruction id stage. (3) at the end of the execution states of a multi-cycle instruction (in the last slot: equivalent to the execution state cycle), parallel execution with the next instruction is possible. parallel execution can be performed even if the next instruction is a 32-bit instruction. (4) a multi-cycle instruction can be executed in parallel with a preceding instruction that is a single-cycle instruction (an instruction with one execution state). a relevant example is shown in figure 8.26. multi-cycle instruction execution in progress ?? last multi-cycle instruction slot ? add r2,r3 if id ex tst #imm,@(r0,gbr) (execution state 3) if id ex ma ex movi20 #imm,r4 if ? id ex figure 8.26 example of multi-cycle instruction execution (5) if a multicycle 32-bit instruction such as band.b, bandnot.b, bld.b, bldnot.b, bor.b, bornot.b, or bxor is followed on the next line by the instruction band.b, bandnot.b, bld.b, bldnot.b, bor.b, bornot.b, or bxor, the instruction on the second line is executed in parallel (figure 8.27).
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 348 of 484 rej09b0051-0300 band.b #imm3, (disp12,rn) if id ex ma ex (execution state 3) bor.b #imm3, (disp12,rn) if ? id ex ma ex figure 8.27 execution example for successive 32-bit bit manipulation instructions (6) except for the cases listed in (5), multicycle 32-bit instructions cannot be executed in parallel with the instruction on the line following them (figure 8.28). band.b #imm3, (disp12,rn) if id ex ma ex (execution state 3) add #imm, rn if ? ? id ex ma ex figure 8.28 multicycle 32-bit instruction execution example 8.3.5 details of contention due to 32-bit instruction the following rules apply to execution of 32-bit instructions. (1) parallel execution is not possible when the preceding instruction is a 32-bit instruction (figure 8.29). (2) when the succeeding instruction is a 32-bit instruction, the preceding instruction can be executed but the succeeding instruction cannot (figure 8.29). (3) the last slot of a multi-cycle instruction and a 32-bit instruction can be executed in parallel (figure 8.26). (4) only in cases where the preceding instruction in the last slot is a multicycle 32-bit instruction such as band.b, bandnot.b, bld.b, bldnot.b, bor.b, bornot.b, or bxor, and the instruction on the next line is band.b, bandnot.b, bld.b, bldnot.b, bor.b, bornot.b, or bxor, does parallel execution take place. parallel execution does not occur in combinations with any other instructions (figures 8.27 and 8.28). (5) a 32-bit instruction cannot be executed unless if has been completed for the upper 16 bits and the lower 16 bits (figure 8.30). relevant examples are shown in figures 8.26 and 8.27.
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 349 of 484 rej09b0051-0300 movi20 #imm,r1 if id ex movi20 #imm,r2 if id ex nop if id figure 8.29 example of 32-bit instruction contention bt (branch taken, to 4n+2) if id ex movi20 #imm,r1 (upper 16 bits) if ? id ex (lower 16 bits) if id figure 8.30 example of 32-bit instruction internal stalling 8.3.6 details of contention due to instruction that uses fpscr if an instruction uses fpscr, parallel execution is not possible with any other instruction if this instruction precedes it. if this instruction follows, parallel execution is not possible with fpu instructions or fpu-related cpu instructions (figure 8.31). add r3,r4 if id ex sts fpscr,r1 if id ex wb sf fadd fr1,fr3 if df e1 e2 sf figure 8.31 example of contention in case of instruction that uses fpscr
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 350 of 484 rej09b0051-0300 8.3.7 details of contention due to branch instruction the following rules apply to contention due to a branch instruction. (1) parallel execution is possible when the branch instruction does not branch. (2) when a branch instruction is supplied as a succeeding instruction, parallel execution with the preceding instruction is possible regardless of the branching situation. (3) when a branch instruction is supplied as a preceding instruction, parallel execution with the succeeding instruction is not possible if a branch occurs. parallel execution is not possible even if if has already been completed for the delay slot (figure 8.32). (4) for the delay slot, id is performed in the next slot in which there is a branch instruction ex stage. (5) execution of a delayed branch instruction is delayed if a fetch has not been performed for the delay slot. a relevant example is shown in figure 8.28. add r3,r4 if id ex jmp @r2 if id ex delay slot if ? id ex branch destination instruction if id figure 8.32 example of contention between branch instructions
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 351 of 484 rej09b0051-0300 8.4 number of instruction execution states the number of execution states of an instruction is counted in the ex stage execution interval. the number of states from the start of instruction 1 ex stage execution until the start of the ex stage of following instruction 2 constitutes the execution time of instruction 1. for example, in the case of the pipeline flow shown in figure 8.33, the ex stage interval of instruction 1 and instruction 2 consists of 4 stages, and therefore the instruction 1 execution time is 4 states. also, the ex stage interval of instruction 2 and instruction 3 consists of 1 states, and therefore the instruction 2 execution time is 1 state. if the program ends at instruction 3, take instruction 4 as the next instruction after instruction 3 in virtual terms, and calculate the execution time of instruction 3 from the ex stages of instruction 3 and instruction 4 in mov rm,rn. (in the example in figure 8.33, the execution time of instruction 3 is 1 state.) the execution time from instruction 1 through instruction 3 in figure 8.33 is a total of 4 + 1 + 1 = 6 states. for the sake of simplicity, this figure does not take super-scalar operation into consideration. ? ? ? ? ? ? ?? ? ? ? (2) (1) (1) (3) (1) (1) (1) instruction 1 if if id ex ma ma ma wb instruction 2 if if id ? ? ex instruction 3 if if ? id ex ma (instruction 4: mov rm,rn if ? id ex ) figure 8.33 example of how to count number of instruction execution states
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 352 of 484 rej09b0051-0300 8.5 effect of memory load instruction on pipeline with an instruction that performs a load from memory, return of data to the destination register is performed in the wb stage at the end of the pipeline. looking at such a load instruction (designated ?load instruction 1? here) and the instruction immediately following it (designated ?instruction 2?), the ex stage of instruction 2 comes before the wb stage of load instruction 1. if, in this case, the destination register of load instruction 1 is used by instruction 2, since the contents of that register have not yet been prepared, execution of the id stage is delayed for a period equivalent to the latency of instruction 1. the same also applies if the destination register of load instruction 1 is the same as the destination, rather than the source, of instruction 2. similarly, execution of the id stage is stalled for an additional slot if the destination of load instruction 1 is the status register (sr) and a flag in sr is fetched and used by instruction 2 (such as addc, for example). when this kind of register contention occurs, the slot in which the destination register can be used is the cycle after completion of the ma stage of instruction 1. this is illustrated in figure 8.34. therefore, if program is written in which an instruction that uses the result of a load instruction is placed immediately after that load instruction, execution speed will decrease. generally, the latency of a load instruction is 2, and therefore speed will not decrease if an instruction that uses the result of a load is placed 3 or 4 instructions after the load instruction. if a memory access instruction is executed as a preceding instruction, the applicable number of instructions is 4 or more, and if executed as a succeeding instruction, 3 or more. load instruction 1 (mov.w @r0,r1) if id ex ma wb instruction 2 (add r1,r3) if ? ? id ex if ? id ex if ? ? id ex figure 8.34 effect of memory load instruction on pipeline
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 353 of 484 rej09b0051-0300 8.6 contention due to fpu when a register (fr0 to fr15, or fpul) that stores the result of a floating-point arithmetic operation instruction, fmov instruction, or floating-point load instruction is read (used as a source register) by a following floating-point arithmetic operation instruction or fmov frm,frn instruction, the next instruction is issued after completion of the operation. as a result, that instruction is kept waiting for a period equivalent to the latency cycle of the preceding operation instruction (figure 8.35). a zero-latency instruction can be executed in parallel with the succeeding instruction even if the succeeding instruction uses the result register as its source (figure 8.36). floating-point arithmetic operation instruction (single-precision) (fadd fr1,fr2) (latency 3) if df e1 e2 sf next floating-point instruction (single-precision) (fmov fr2,fr3) if ? ? df ex na sf figure 8.35 example of use of fpu operation result by succeeding instruction floating-point instruction (single-precision) (fmov fr0,fr2) (latency 0) if df ex na sf next floating-point arithmetic operation instruction (single-precision) (fadd fr2,fr3) if df e1 e2 sf figure 8.36 example of use of result of zero-latency instruction as source when a register (fr0 to fr15) that stores the result of a floating-point arithmetic operation instruction is read (used as a source register) by a following fmov or sts.l instruction, and the value is output to memory, latency is shortened by 1 cycle (figure 8.37). floating-point arithmetic operation instruction (single-precision) (fadd fr0,fr2) if df e1 e2 sf next floating-point instruction (single-precision) (fmov fr2,@r3) if ? df ex na figure 8.37 example of writing result to memory immediately following fpu operation
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 354 of 484 rej09b0051-0300 when a register (fpul) that stores the result of a floating-point arithmetic operation instruction is read (used as a source register) by a following sts instruction, and the value is output to the cpu, latency is shortened by 2 cycles (figure 8.38). floating-point arithmetic operation instruction (single-precision) (ftrc fr0,fpul) if df e1 e2 sf next floating-point instruction (single-precision) (sts fpul,r3) if df ex na figure 8.38 example of transferring result to cpu immediately following fpu operation the time required for the result of an fcmp instruction to be reflected in the t bit is 2 cycles in the case of single-precision, and 3 cycles in the case of double-precision. as a result, if that instruction (the following instruction) references the t bit, execution is delayed by the above slot interval (figure 8.39). instruction 1 (single-precision) (fcmp fr0,fr1) if df e1 e2 instruction 2 (instruction that references t bit) (bf) if ? id ex figure 8.39 example of referencing t bit immediately after fcmp instruction when the fpscr value is changed using an lds or lds.l instruction, execution of the next instruction by a 3-slot interval (figure 8.40). instruction 1 (lds r2,fpscr) if df ex na sf instruction 2 (fadd fr4,fr5) if ? ? ? df e1 e2 sf figure 8.40 example of performing fpu operation immediately after fpscr load
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 355 of 484 rej09b0051-0300 when the fpscr value is read using an sts or sts.l instruction, fpscr is read after completion of the previously issued operation. as a result, execution is delayed by an interval of [latency of preceding operation + 1 slot] (figure 8.41). instruction 1 (single-precision) (fadd fr6,fr9) if df e1 e2 sf instruction 2 (sts fpscr,r3) if ???dfexnasf figure 8.41 example of reading fpscr double-precision floating-point arithmetic operation instructions (fadd, fsub, fmul) require 6 cycles for the e1 stage. another floating-point arithmetic operation instruction will not enter the e1 stage during this interval. if another floating-point arithmetic operation instruction appears before a double-precision floating-point arithmetic operation instruction finishes the e1 stage, that floating-point arithmetic operation instruction has its execution delayed by a predetermined slot interval, and enters the e1 stage after the double-precision floating-point arithmetic operation instruction has finished the e1 stage. a floating-point load/store instruction arriving during this interval can be executed (figure 8.42). fadd dr4,dr6 if df e1 e1 e1 e1 e1 e1 e2 sf fabs dr0 if df ex na sf sts fpul,r0 if df ex na fmul dr2,dr0 if ? ? ? ? ? df e1 e2 sf figure 8.42 example of double-precision fpu operation and next fpu instruction with an fdiv or fsqrt instruction, after the e1 stage is used in initialization, operation is performed by an independent computer (ed stage), after which the operation result is written back. a floating-point arithmetic operation instruction following either of these instructions operates as described below. see section 8.9, pipeline operations for each instruction, for the kind of pipeline used with each instruction. (1) during e1 stage use in initialization, another floating-point arithmetic operation instruction will not enter the e1 stage. other instructions enter the e1 stage after fdiv or fsqrt initialization ends. (2) after an fdiv or fsqrt instruction has progressed to the ed stage, an fpu instruction is executed without delay unless it uses the fdiv or fsqrt instruction result register (figure 8.40).
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 356 of 484 rej09b0051-0300 (3) at the end of an fdiv or fsqrt instruction, operation write-back occurs. the e1 stage is used again here, and therefore if an instruction requests e1 stage operation from just this point onward, the subsequent instruction is kept waiting until the fdiv or fsqrt instruction finishes using the e1 stage (figure 8.44). (4) an fdiv or fsqrt instruction immediately following an fdiv or fsqrt instruction cannot enter the ed stage while the preceding fdiv or fsqrt instruction is using the ed stage. instruction 1 (single-precision) (fdiv fr6,fr7) if df e1 ed ed ed ed ed ed ed ed e1 e2 sf instruction 2 (single-precision) (fadd fr8,fr10) if df e1 e2 sf figure 8.43 example 1 of e1 stage contention due to fdiv instruction 1 (single-precision) (fdiv fr6,fr7) if df e1 ed ed ed ed ed ed ed ed e1 e2 sf other instruction : instruction 2 (single-precision) (fadd fr8,fr10) if df e1 e2 sf instruction 3 (single-precision) (fadd fr9,fr11) if ? df e1 e2 sf figure 8.44 example 2 of e1 stage contention due to fdiv if a write was performed by a previous instruction on a register used as a source register by a double-precision arithmetic operation instruction, and the latency of the previous instruction is 2 cycles or less, the latency of those instructions will be 2 (figure 8.45).
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 357 of 484 rej09b0051-0300 floating-point load/store instruction (double- precision) (fmov dr0,dr2) (latency 1 latency 2) if df ex na sf next floating-point arithmetic operation instruction (double- precision) (fadd dr2,dr4) if ? ? df e1 e1 ? ?? ? ? ?? ? ? ?? ? e1 e2 sf figure 8.45 example of 1-latency instruction immediately preceding double-precision arithmetic operation if the destination register of a double-precision arithmetic operation instruction is used as a source register by the following instruction, if ?n? of frn is an odd number, latency will be reduced by 1 cycle (figure 8.46). however, latency will not be reduced if ?n? of frn is an even number (figure 8.47). floating-point arithmetic operation instruction (double-precision) (fadd dr0,dr2) (latency 8 latency 7) if df e1 e1 e1 e1 e1 e1 e2 sf next floating-point load/store instruction (single-precision) (fmov fr3,fr5) if ? ? ? ? ? df ex na sf figure 8.46 example of latency reduction with double-precision arithmetic operation instruction
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 358 of 484 rej09b0051-0300 floating-point arithmetic operation instruction (double-precision) (fadd dr0,dr2) (remains at latency 8) if df e1 e1 e1 e1 e1 e1 e2 sf next floating-point load/store instruction (single-precision) (fmov fr2,fr4) if ??????dfexnasf figure 8.47 example of no latency reduction with double-precision arithmetic operation instruction when a register (fr0 to fr15, or fpul) that stores the result of a floating-point arithmetic operation instruction is written to (used as a destination register) by a following floating-point arithmetic operation instruction or floating-point load/store instruction, the next instruction is kept waiting before being executed. the number of cycles by which execution is delayed is [latency ? 1] cycles if the preceding operation was fdiv or fsqrt, and [latency ? 2] cycles otherwise (figures 8.48 and 8.49). floating-point arithmetic operation instruction (single-precision) (fdiv fr1,fr2) (latency 12 latency 11) ? ?? ? ? ?? ? ? ?? ? ed e1 e2 sf next floating-point load/store instruction (single-precision) (fmov fr3,fr2) ? ? df ex na sf figure 8.48 example of contention due to overwriting (fdiv, fsqrt)
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 359 of 484 rej09b0051-0300 floating-point arithmetic operation instruction (single-precision) (fadd fr1,fr2) (latency 3 latency 1) ? ?? ? ? ?? ? ? ?? ? df e1 e2 sf next floating-point instruction (single- precision) (fmov fr2,fr2) ?dfexnasf figure 8.49 example of contention due to overwriting (except fdiv, fsqrt) if a write is performed by the following instruction on the register used as a source register by a double-precision fadd, fsub, or fmul, the following will be kept waiting for 2 cycles (figure 8.50). floating-point arithmetic operation instruction (double-precision) (fadd dr0,dr2) (latency 0 latency 2) if df e1 e1 e1 e1 e1 e1 e2 sf next floating-point load/store instruction (single-precision) (fmov fr4,fr1) if ? ? df ex na sf figure 8.50 example of write to double-precision instruction source immediately after double-precision operation
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 360 of 484 rej09b0051-0300 8.7 contention due to multiplier multiply instructions, multiply-and-accumulate instructions, and instructions that manipulate the registers for these instructions (mach, macl) use the multiplier. in addition, the sts fpul,rn, and sts fpscr,rn instructions use the multiplication result read bus. details of pipelining and contention are given below, with instructions divided into the categories shown. the numbers immediately following the instructions, in the form (a/b/c), indicate (number of execution slots/latency/number of lock slots). ? multiply-and-accumulate instructions mac.l (4/6/5) if id ex ma ma mm mm mm mac.w (3/5/4) if id ex ma ma mm mm ? multiply instructions (i) dmul.s, dmul.u, mul.l (2/3/2) if id mm mm mm muls.w, mulu.w(1/2/1) if id mm mm ? multiply instructions (ii) (register return) mulr (2/4/2) if id mmmmmmwb ? register write instructions (i) clrmac, lds (1/2/1) if id mm mm ? register write instructions (ii) lds.l (1/3/2) if id ex ma wb ? register read instructions (including sts fpul,rn and sts fpscr,rn) sts (1/2/0) if id ex wb sts.l (1/2/0) if id ex ma facts about contention contention arises with multi-cycle instructions in the same way as with general instructions (figure 8.51). see section 8.3.4, details of contention due to multi-cycle instruction, for details. mac.l @r1+,@r2+ if id ex ma ma mm mm mm mac.l @r3+,@r4+ if ? ? ? id ex ma ma mm mm mm note: mac.l is an instruction with an execution rate of 4. figure 8.51 example of multi-cycle instructions using multiplier the following rules apply to instructions that use the multiplier.
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 361 of 484 rej09b0051-0300 (1) execution of a instruction that uses a multiplication result as its source is delayed by an interval equivalent to the latency of that instruction (figure 8.52). if the following instruction is one that reads mach or macl, execution is delayed by [latency ? 1] cycled (figure 8.53). if the following instruction is a multiply-and-accumulate instruction, execution is not delayed (figure 8.54). mulrr0,r4 if id mmmmmmwb add r4,r5 if ? ? ? ? id ex wb figure 8.52 example of referencing result register immediately after multiplication (1) mul.l r2,r3 if id mm mm mm sts mach,r4 if ? ? id ex wb figure 8.53 example of referencing result register immediately after multiplication (2) mac.w @r1+,@r2+ if id ex ma ma mm mm mac.w @r3+,@r4+ if ? ? id ex ma ma mm mm figure 8.54 example of referencing result register immediately after multiplication (3) (2) in the case of an instruction after an instruction that uses the multiplier, if the preceding instruction locked the multiplier, execution is delayed until the multiplier is unlocked (figure 8.55). mulr1 lock interval ? ? ? ? mulr1 r0,r1 if id mm mm mm wb mulr2 r0,r2 if ? ? id mm mm mm wb figure 8.55 example of multiplier lock contention however, if the following instruction is a multiply-and-accumulate instruction, it is executed after waiting for the same kind of state interval as with an ordinary multi-cycle instruction, rather than after waiting for the multiplier to be unlocked (figure 8.56).
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 362 of 484 rej09b0051-0300 mulr1 lock interval ? ? ? ? mulr1 r0,r1 if id mm mm mm wb mac.l @r3+,@r4+ if ? id ex ma ma mm mm mm figure 8.56 example of no multiplier lock contention when following instruction is multiply-and-accumulate instruction if the following instruction is an instruction in category ?register write instructions (ii),? it is executed when there is one slot remaining in the lock interval (figure 8.57). mac.l lock interval ????? lock interval with lds.l instruction ??? ? ??? ? ??? ? ??? ? mac.l @r1+,@r2+ if id ex ma ma mm mm mm lds.l@r3+,mach if????idexmawb figure 8.57 example of unlocking 1 state earlier sts and sts.l instructions do not lock the multiplier. therefore, parallel execution is possible for an sts instruction and mul.l instruction, etc. mul.l r1,r2 if id mm mm mm sts mach,r3 if ? ? id ex wb mul.l r4,r5 if ? id mm mm mm sts macl,r6 if ? ? ? id ex wb mulrr0,r7 if ? ? id mmmmmmwb figure 8.58 example of parallel execution of sts instruction and mul.l instruction
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 363 of 484 rej09b0051-0300 (3) mulr instructions, sts instructions affecting mach, macl, fpul, or fpscr, and sts.l instructions affecting mach or macl chare a result register read bus, causing resource contention (ma and wb stages). therefore, parallel execution is not possible for sts and sts.l instructions (figure 8.59). if an sts or sts.l is located immediately after a mulr instruction, wb stage contention occurs in the same way, and execution of the sts or sts.l instruction is delayed by 3 cycles (figure 8.60). mul.l r1,r2 if id mm mm mm sts mach,r3 if ? ? id ex wb sts.l macl,@-r4 if ? ? id ex ma figure 8.59 example of contention with sts and sts.l mul.l r1,r2 if id mm mm mm mulrr0,r3 if ? ? id mmmmmmwb sts mach,r4 if ? ? ? ? id ex wb figure 8.60 example of contention between mulr and sts
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 364 of 484 rej09b0051-0300 8.8 programming strategy the following programming points should be noted in order to improve instruction execution speed. (1) a branch destination address should be at a longword boundary in memory. this enables parallel execution to be performed efficiently immediately after a branch. (2) the first 3 instructions immediately after an instruction that performs a load from memory should not include an instruction that uses the same register as the load instruction destination register. if possible, an instruction that uses the destination register should be no earlier than the fourth instruction after the load instruction. (3) the first 3 instructions immediately after a 32-bit multiply instruction should not include an instruction that uses the same register as the result register. (4) instructions immediately following a floating-point arithmetic operation instruction, and having a latency between 1 and twice the latency of the floating-point arithmetic operation instruction, should not use the destination register of the floating-point arithmetic operation instruction. 8.9 pipeline operations for each instruction pipeline operations for each instruction are described below. in conjunction with the previously described rules and possibility of parallel execution, this information allows the program pipeline flow and number of instruction execution states to be calculated. ?instruction a? in the following pipeline diagrams denotes the instruction being described. the ?instruction issuance? description indicates in particular how the instruction should be treated when taking resource contention into consideration. the ?parallel execution capability? description indicates in particular how the instruction should be treated when taking parallel execution capability into consideration. cases are described here in which there is no register contention. the number of stages and number of execution states of an instruction are indicated using the format below. these tables show the number of states when the instruction is executed without register dependency.
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 365 of 484 rej09b0051-0300 format of number of instruction stages and execution states type category number of stages execution states latency contention instructions type according to function instructions are categorized according to differences of operation. number of instruction stages number of execution states when there is no contention number of execution states until execution result is confirmed resource contention that occurs applicable instructions, indicated by mnemonic table 8.1 number of instruction stages and execution states type category number of stages execution states latency contention instructions 311 ? mov #imm,rn 1 0 mov rm,rn 1 1 mova @(disp,pc),r0 data transfer instructions register- register transfer instructions movt rn movrt rn nott swap.b rm,rn swap.w rm,rn xtrct rm,rn movi20 #imm,rn ? these are 32-bit instructions. movi20s #imm20,rn
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 366 of 484 rej09b0051-0300 type category number of stages execution states latency contention instructions 5 1 2 mov.w @(disp,pc),rn mov.l @(disp,pc),rn data transfer instructions memory load instructions mov.b @rm,rn ? these instruc- tions use the memory access pipeline. mov.w @rm,rn mov.l @rm,rn mov.b @rm+,rn mov.w @rm+,rn mov.l @rm+,rn mov.b @-rm,r0 mov.w @-rm,r0 mov.l @-rm,r0 mov.b @(disp,rm),r0 mov.w @(disp,rm),r0 mov.l @(disp,rm),rn mov.b @(r0,rm),rn mov.w @(r0,rm),rn mov.l @(r0,rm),rn mov.b @(disp,gbr),r0 mov.w @(disp,gbr),r0 mov.l @(disp,gbr),r0 5 to 20 1 to 16 2 to 17 movml.l @r15+,rn movmu.l @r15+,rn 5 1 2 mov.b @(disp12,rm),rn mov.w @(disp12,rm),rn mov.l @(disp12,rm),rn movu.b @(disp12,rm),rn ? these are 32-bit instructions. ? these instruc- tions use the memory access pipeline. movu.w @(disp12,rm),rn
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 367 of 484 rej09b0051-0300 type category number of stages execution states latency contention instructions 4 1 0 mov.b rm,@rn mov.w rm,@rn data transfer instructions memory store instructions ? these instruc- tions use the memory access pipeline. mov.l rm,@rn 1 mov.b rm,@-rn mov.w rm,@-rn mov.l rm,@-rn mov.b r0,@rn+ mov.w r0,@rn+ mov.l r0,@rn+ 0 mov.b r0,@(disp,rn) mov.w r0,@(disp,rn) mov.l rm,@(disp,rn) mov.b rm,@(r0,rn) mov.w rm,@(r0,rn) mov.l rm,@(r0,rn) mov.b r0,@(disp,gbr) mov.w r0,@(disp,gbr) mov.l r0,@(disp,gbr) 4 to 19 1 to 16 1 to 16 movml.l rm,@-r15 movmu.l rm,@-r15 4 1 0 mov.b rm,@(disp12,rn) mov.w rm,@(disp12,rn) ? these are 32-bit instructions. ? these instruc- tions use the memory access pipeline. mov.l rm,@(disp12,rn) pref instruction 4 1 0 ? this instruction uses the memory access pipeline. pref @rm
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 368 of 484 rej09b0051-0300 type category number of stages execution states latency contention instructions 311 ? add rm,rn add #imm,rn addc rm,rn addv rm,rn arithmetic operation instructions cmp/eq #imm,r0 cmp/eq rm,rn cmp/hs rm,rn cmp/ge rm,rn inter- register arithmetic operation instructions (excluding multiply instruc- tions) cmp/hi rm,rn cmp/gt rm,rn cmp/pz rn cmp/pl rn cmp/str rm,rn div1 rm,rn div0s rm,rn div0u dt rn exts.b rm,rn exts.w rm,rn extu.b rm,rn extu.w rm,rn neg rm,rn negc rm,rn sub rm,rn subc rm,rn inter- register arithmetic operations instructions (excluding multiply instructions and divu or divs instruc- tions) subv rm,rn clipu.b rn clipu.w rn clips.b rn clip instructions 311 ? clips.w rn
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 369 of 484 rej09b0051-0300 type category number of stages execution states latency contention instructions arithmetic operation instructions multiply- and- accumulate instruction 7 3 4 ? this instruction locks the multiplier for 4 states. mac.w @rm+,@rn+ double- precision multiply- and- accumulate instruction 8 4 5 ? this instruction locks the multiplier for 5 states. mac.l @rm+,@rn+ 4 1 2 muls.w rm,rn multiply instructions ? these instruc- tions lock the multiplier for 2 states. mulu.w rm,rn 5 2 3 dmuls.l rm,rn dmulu.l rm,rn mul.l rm,rn double- precision multiply instructions 624 ? these instruc- tions lock the multiplier for 2 states. mulr r0,rn divu instruction 36 34 34 ? these instruc- tions use the shift register. divu r0,rn divs instruction 38 36 36 ? divs r0,rn 311 ? and rm,rn and #imm,r0 not rm,rn logical operation instructions register- register logical operation instructions or rm,rn or #imm,r0 tst rm,rn tst #imm,r0 xor rm,rn xor #imm,r0 6 3 2 and.b #imm,@(r0,gbr) or.b #imm,@(r0,gbr) 5 3 tst.b #imm,@(r0,gbr) memory logical operation instructions 62 ? these instruc- tions use the memory access pipeline. xor.b #imm,@(r0,gbr) tas instruction 6 3 3 ? this instruction uses the memory access pipeline. tas.b @rn
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 370 of 484 rej09b0051-0300 type category number of stages execution states latency contention instructions bld #imm3,rn bset #imm3,rn bclr #imm3,rn bit manipula- tion instructions register- register bit operation instructions 311 ? bst #imm3,rn band.b #imm3,@(disp12,rn) bandnot.b #imm3,@(disp12,rn) bor.b #imm3,@(disp12,rn) bornot.b #imm3,@(disp12,rn) bld.b #imm3,@(disp12,rn) bldnot.b #imm3,@(disp12,rn) memory- t-bit bit operation instructions 533 bxor.b #imm3,@(disp12,rn) bst.b #imm3,@(disp12,rn) bclr.b #imm3,@(disp12,rn) memory bit manipula- tion instructions 632 ? these are 32-bit instructions. ? these instruc- tions use the memory access pipeline. bset.b #imm3,@(disp12,rn) 311 rotlrn shift instructions rotr rn rotcl rn shift instructions ? these instruc- tions use the shift pipeline. rotcr rn shal rn shar rn shll rn shlr rn shll2 rn shlr2 rn shll8 rn shlr8 rn shll16 rn shlr16 rn shad rm,rn shld rm,rn
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 371 of 484 rej09b0051-0300 type category number of stages execution states latency contention instructions 33/1 * 1 3/1 * 1 bf label branch instructions conditional branch instructions ? these instruc- tions use the branch pipeline. bt label 32/1 * 1 2/1 * 1 bs/f label delayed conditional branch instructions ? these instruc- tions use the branch pipeline. bt/s label 3 2 2 bra label braf rm unconditio nal branch instructions bsr label ? these instruc- tions use the branch pipeline. bsrf rm jmp @rm jsr @rm rts 333 jsr/n@rm rts/n ? these instruc- tions use the branch pipeline. rtv/n rm unconditio nal branch instructions with no delay 5 5 5 ? this instruction uses the branch pipeline. ? this instruction uses the memory access pipeline. jsr/n @@(disp,tbr) 311 ? clrt 5 3 2 ldc rm,sr 311 ? ldc rm,gbr system control instructions system control alu instructions ldc rm,tbr ldc rm,vbr lds rm,pr 0nop sett 422 stcsr,rn 3 1 1 stc gbr,rn stc tbr,rn stc vbr,rn sts pr,rn
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 372 of 484 rej09b0051-0300 type category number of stages execution states latency contention instructions 7 5 4 ldc.l @rm+,sr 5 1 2 ldc.l @rm+,gbr ldc.l instructions ? these instruc- tions use the memory access pipeline. ldc.l @rm+,vbr 5 2 2 stc.l sr,@-rn 4 1 1 stc.l gbr,@-rn system control instructions stc.l instructions ? these instruc- tions use the memory access pipeline. stc.l vbr,@-rn lds.l instruction (pr) 5 1 2 ? this instruction uses the memory access pipeline. lds.l @rm+,pr sts.l instruction (pr) 4 1 1 sts.l pr,@-rn 411 clrmac lds rm,mach register mac transfer instructions ? these instruc- tions lock the multiplier for 1 state. lds rm,macl 5 1 2 lds.l @rm+,mach memory mac transfer instructions ? these instruc- tions lock the multiplier for 2 states. lds.l @rm+,macl 4 1 2 sts mach,rn mac register transfer instructions ? these instruc- tions use the multiplication result read path. sts macl,rn 4 1 1 sts.l mach,@-rn mac memory transfer instructions ? these instruc- tions use the multiplication result read path. sts.l macl,@-rn rte instruction 865 ? rte resbank instruction 11/23 * 2 9/19 * 2 8/20 * 2 ? when the bo bit is 1, this instruction uses the memory access pipeline. resbank ldbank instruction 865 ? ldbank @rm,r0 stbank instruction 976 ? stbank r0,@rn
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 373 of 484 rej09b0051-0300 type category number of stages execution states latency contention instructions trap instruction 856 ? trapa #imm system control instructions sleep instruction 750 ? sleep 11 ? lds rm,fpul fpu load/store instructions fpu load instructions 5 2 ? these instruc- tions use the memory access pipeline. lds.l @rm+,fpul 3 ? lds rm,fpscr fpscr load instructions 51 3 ? these instruc- tions use the memory access pipeline. lds.l @rm+,fpscr fpul store instruction (sts) 4 1 2 ? this instruction uses the multiplication result read path. sts fpul,rn fpul store instruction (sts.l) 4 1 2 ? this instruction uses the memory access pipeline. sts.l fpul,@-rn fpscr store instruction (sts) 4 1 2 ? this instruction uses the multiplication result read path. sts fpscr,rn fpscr store instruction (sts.l) 4 1 1 ? this instruction uses the memory access pipeline. sts.l fpscr,@-rn
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 374 of 484 rej09b0051-0300 type category number of stages execution states latency contention instructions 510 fldsfrm,fpul fmov frm,frn floating- point register- register transfer instructions ? these instruc- tions use the fpu load/store pipeline. fsts fpul,frn single- precision floating- point instructions 1 0 fldi0 frn floating- point register- immediate instructions 5 ? these instruc- tions use the fpu load/store pipeline. fldi1 frn fschg instruction 5 1 1 ? this instruction uses the fpu arithmetic operation pipeline. fschg 510/2 * 3 fmov.s @rm,frn 11/2 * 3 fmov.s @rm+,frn floating- point register load instructions 0/2 * 3 ? these instruc- tions use the fpu load/store pipeline and memory access pipeline. fmov.s @(r0,rm),frn 410/2 * 3 ? this is 32-bit instruction. ? this instruction uses the fpu load/store pipeline and memory access pipeline. fmov.s @(disp12,rm),frn 410 fmov.sfrm,@rn 1/0 * 3 fmov.s frm,@-rn floating- point register store instructions 0 ? these instruc- tions use the fpu load/store pipeline and memory access pipeline. fmov.s frm,@ (r0,rn) ? this is 32-bit instruction. ? this instruction uses the fpu load/store pipeline and memory access pipeline. fmov.s frm,@(disp12,rn)
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 375 of 484 rej09b0051-0300 type category number of stages execution states latency contention instructions 5 1 fadd frm,frn float fpul,frn fmac fr0,frm,frn fmul frm,frn single- precision floating- point instructions floating- point operation instructions (excluding fdiv) fsub frm,frn 3 ? these instruc- tions use the fpu arithmetic operation pipeline. ftrc frm,fpul 5 1 fabs frn 0 ? these instruc- tions use the fpu load/store pipeline. fneg frn 14 1 12 fdiv frm,frn floating- point operation instructions (fdiv, fsqrt) 13 1 11 ? these instruc- tions use the fpu arithmetic operation pipeline and fpu division/ square root extraction pipeline. fsqrt frn fcmp/eq frm,frn floating- point compare instructions 4 1 2 ? these instruc- tions use the fpu arithmetic operation pipeline. fcmp/gt frm,frn
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 376 of 484 rej09b0051-0300 type category number of stages execution states latency contention instructions double- precision floating- point instructions floating- point register- register transfer instructions 6 2 1 ? these instruc- tions use the fpu load/store pipeline. fmov drm,drn 1 4 fcnvsd fpul,drn floating- point register- immediate instructions 5 ? these instruc- tions use the fpu arithmetic operation pipeline. fcnvds drm,fpul 6 2 0/2/3/4 * 4 fmov.d @rm,drn 1/2/3/4 * 4 fmov.d @rm+,drn floating- point register load instructions 0/2/3/4 * 4 ? these instruc- tions use the fpu load/store pipeline and memory access pipeline. fmov.d @(r0,rm),drn ? this is 32-bit instruction. ? this instruction uses the fpu load/store pipeline and memory access pipeline. fmov.d @(disp12,rm),drn 5 2 0 fmov.d drm,@rn 1/0 * 3 fmov.d drm,@-rn floating- point register store instructions 0 ? these instruc- tions use the fpu load/store pipeline and memory access pipeline. fmov.d drm,@ (r0,rn) ? this is 32-bit instruction. ? this instruction uses the fpu load/store pipeline and memory access pipeline. fmov.d drm,@(disp12,rn)
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 377 of 484 rej09b0051-0300 type category number of stages execution states latency contention instructions 10 1 0/8/7/8 * 4 fadd drm,drn fmul drm,drn fsub drm,drn 610/4 * 3 ftrc drm,fpul double- precision floating- point instructions 61 0/4/3/4 * 4 ? these instruc- tions use the fpu arithmetic operation pipeline. float fpul,drn floating- point operation instructions (excluding fdiv) 5 1 fabs drn 0 ? these instruc- tions use the fpu load/store pipeline. fneg drn 27 1 0/25/24/ 25 * 4 fdiv drm,drn floating- point operation instructions (fdiv, fsqrt) 26 1 0/24/23/ 24 * 4 ? these instruc- tions use the fpu arithmetic operation pipeline and fpu division/ square root extraction pipeline. floating-point compare instructions fsqrt drn fcmp/eq drm,drn floating- point compare instructions 4 2 3 ? these instruc- tions use the fpu arithmetic operation pipeline. fcmp/gt drm,drn notes: 1. 1 state when a branch is not performed. 2. number of stages, execution states, and latency are shown in bo bit = 0/bo bit = 1 order. 3. latency is shown in cpu register/fpu register order. 4. latency is shown in the following order: in case of use as cpu register/single-precision register; in case of use as frn even number side/single-precision register; in case of use as frn odd number side/double-precision register.
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 378 of 484 rej09b0051-0300 8.9.1 data transfer instructions (1) register-register transfer instructions (mov rm,rn) instruction type mov rm,rn pipeline ????? slots instruction a if id ex next instruction if id ex ? ?? ? ? ?? ? ? ?? ? instruction after next if id ex ? ?? ? ? ?? ? ? ?? ? operation the pipeline ends after three stages: if, id, ex. in the ex stage, data transfer is performed via the alu. instruction issuance this instruction does not cause resource contention. parallel execution capability this is a zero-latency instruction. parallel execution is possible even when this instruction is executed as a preceding instruction and the succeeding instruction uses rn.
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 379 of 484 rej09b0051-0300 (2) register-register transfer instructions (20-bit immediate value) instruction types movi20 #imm20,rn movi20s #imm20,rn pipeline ????? slots instruction a if id ex next instruction if id ex ? ?? ? ? ?? ? ? ?? ? instruction after next if id ex ? ?? ? ? ?? ? ? ?? ? operation the pipeline ends after three stages: if, id, ex. in the ex stage, data transfer is performed via the alu. instruction issuance these instructions do not cause resource contention. parallel execution capability these are 32-bit instructions, and cannot be used in parallel execution. (see section 8.3.5, details of contention due to 32-bit instruction.)
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 380 of 484 rej09b0051-0300 (3) register-register transfer instructions (excluding mov rm,rn, mov120, and mov120s) instruction types mov #imm,rn mova @(disp,pc),r0 movt rn movrt rn swap.b rm,rn swap.w rm,rn xtrct rm,rn nott rn pipeline ????? slots instruction a if id ex next instruction if id ex ? ?? ? ? ?? ? ? ?? ? instruction after next if id ex ? ?? ? ? ?? ? ? ?? ? operation the pipeline ends after three stages: if, id, ex. in the ex stage, data transfer is performed via the alu. instruction issuance the swap.b, swap.w, and xtrct instructions use the shifter. the other instructions do not cause resource contention. parallel execution capability no particular comments
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 381 of 484 rej09b0051-0300 (4) memory load instructions instruction types mov.w @(disp,pc),rn mov.l @(disp,pc),rn mov.b @rm,rn mov.w @rm,rn mov.l @rm,rn mov.b @rm+,rn mov.w @rm+,rn mov.l @rm+,rn mov.b @-rm,r0 mov.w @-rm,r0 mov.l @-rm,r0 mov.b @(disp,rm),r0 mov.w @(disp,rm),r0 mov.l @(disp,rm),rn mov.b @(r0,rm),rn mov.w @(r0,rm),rn mov.l @(r0,rm),rn mov.b @(disp,gbr),r0 mov.w @(disp,gbr),r0 mov.l @(disp,gbr),r0 pipeline ????? slots instruction a if id ex ma wb next instruction if id ex ? ?? ? ? ?? ? ? ?? ? instruction after next if id ex ? ?? ? ? ?? ? ? ?? ? operation the pipeline has five stages: if, id, ex, ma, wb. contention may occur if an instruction that uses the destination register of this instruction is among the three instructions following this instruction. (see section 8.5, effect of memory load instruction on pipeline.) instruction issuance these instructions use the memory access pipeline.
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 382 of 484 rej09b0051-0300 parallel execution capability no particular comments
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 383 of 484 rej09b0051-0300 (5) memory load instructions (12-bit displacement) instruction types mov.b @(disp12,rm),rn mov.w @(disp12,rm),rn mov.l @(disp12,rm),rn movu.b @(disp12,rm),rn movu.w @(disp12,rm),rn pipeline ????? slots instruction a if id ex ma wb next instruction if id ex ? ?? ? ? ?? ? ? ?? ? instruction after next if id ex ? ?? ? ? ?? ? ? ?? ? operation the pipeline has five stages: if, id, ex, ma, wb. contention may occur if an instruction that uses the destination register of this instruction is located within the 2 instructions following this instruction. (see section 8.5, effect of memory load instruction on pipeline.) instruction issuance these instructions use the memory access pipeline. parallel execution capability these are 32-bit instructions, and cannot be executed in parallel with a subsequent instruction. (see section 8.3.5, details of contention due to 32-bit instruction.)
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 384 of 484 rej09b0051-0300 (6) memory load instructions (movmu.l, movml.l) instruction types movmu.l @r15+,rn movml.l @r15+,rn pipeline ????????? slots instruction a if id ex ma ? ?? ? ? ?? ? ? ?? ? ma ma ma wb next instruction if ? ? ? ? ?? ? ? ?? ? ? ?? ? id ex ? ?? ? ? ?? ? ? ?? ? instruction after next if ? ? ? ?? ? ? ?? ? ? ?? ? ?idex ? ?? ? ? ?? ? ? ?? ? operation these instructions perform restoration from the stack. the pipeline is in the form if, id, ex, ma, ma, ma, ... ma, wb, with ma repeated as often as necessary. contention may occur if an instruction that uses the destination register of this instruction is located within the 3 instructions following this instruction. (see section 8.5, effect of memory load instruction on pipeline.) instruction issuance if there is an uncompleted instruction in the pipeline when these instructions are decoded, execution of these instructions will be delayed. these instructions use the memory access pipeline. parallel execution capability these are multi-cycle instructions, and cannot be executed in parallel with a subsequent instruction. (see section 8.3.4, details of contention due to multi-cycle instruction.)
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 385 of 484 rej09b0051-0300 (7) memory store instructions instruction types mov.b rm,@rn mov.w rm,@rn mov.l rm,@rn mov.b rm,@-rn mov.w rm,@-rn mov.l rm,@-rn mov.b r0,@rn+ mov.w r0,@rn+ mov.l r0,@rn+ mov.b r0,@(disp,rn) mov.w r0,@(disp,rn) mov.l rm,@(disp,rn) mov.b rm,@(r0,rn) mov.w rm,@(r0,rn) mov.l rm,@(r0,rn) mov.b r0,@(disp,gbr) mov.w r0,@(disp,gbr) mov.l r0,@(disp,gbr) pipeline ????? slots instruction a if id ex ma next instruction if id ex ? ?? ? ? ?? ? ? ?? ? instruction after next if id ex ? ?? ? ? ?? ? ? ?? ? operation the pipeline ends after four stages: if, id, ex, ma. there is no wb stage as there is no return of data to the register. instruction issuance these instructions use the memory access pipeline.
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 386 of 484 rej09b0051-0300 parallel execution capability no particular comments
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 387 of 484 rej09b0051-0300 (8) memory store instructions (12-bit displacement) instruction types mov.b rm,@(disp12,rn) mov.w rm,@(disp12,rn) mov.l rm,@(disp12,rn) pipeline ????? slots instruction a if id ex ma next instruction if ? id ex ? ?? ? ? ?? ? ? ?? ? instruction after next if id ex ? ?? ? ? ?? ? ? ?? ? operation the pipeline ends after four stages: if, id, ex, ma. there is no wb stage as there is no return of data to the register. instruction issuance these instructions use the memory access pipeline. parallel execution capability these are 32-bit instructions, and cannot be used in parallel execution. (see section 8.3.5, details of contention due to 32-bit instruction.)
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 388 of 484 rej09b0051-0300 (9) memory store instructions (movmu.l, movml.l) instruction types movmu.l rm,@-r15 movml.l rm,@-r15 pipeline ???????? slots instruction a if id ex ma ? ?? ? ? ?? ? ? ?? ? ma ma ma next instruction if ? ? ? ? ?? ? ? ?? ? ? ?? ? id ex ? ?? ? ? ?? ? ? ?? ? instruction after next if ? ? ? ?? ? ? ?? ? ? ?? ? ?idex ? ?? ? ? ?? ? ? ?? ? operation these instructions perform saving to the stack. the pipeline is in the form if, id, ex, ma, ma, ma, ... ma, with ma repeated as often as necessary. there is no wb stage as there is no return of data to the register. instruction issuance if there is an uncompleted instruction in the pipeline when these instructions are decoded, execution of these instructions will be delayed. these instructions use the memory access pipeline. parallel execution capability these are multi-cycle instructions, and cannot be executed in parallel with a subsequent instruction.
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 389 of 484 rej09b0051-0300 (10) pref instruction instruction type pref @rm pipeline ????? slots instruction a if id ex ma next instruction if id ex ? ?? ? ? ?? ? ? ?? ? instruction after next if id ex ? ?? ? ? ?? ? ? ?? ? operation the pipeline ends after four stages: if, id, ex, ma. there is no wb stage as there is no return of data to the register. instruction issuance this instruction uses the memory access pipeline. parallel execution capability no particular comments
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 390 of 484 rej09b0051-0300 8.9.2 arithmetic operation instructions (1) inter-register arithmetic operation instructions (excluding multiply instructions and divu or divs instructions) instruction types add rm,rn add #imm,rn addc rm,rn addv rm,rn cmp/eq #imm,r0 cmp/eq rm,rn cmp/hs rm,rn cmp/ge rm,rn cmp/hi rm,rn cmp/gt rm,rn cmp/pz rn cmp/pl rn cmp/str rm,rn div1 rm,rn div0s rm,rn div0u dt rn exts.b rm,rn exts.w rm,rn extu.b rm,rn extu.w rm,rn neg rm,rn negc rm,rn sub rm,rn subc rm,rn subv rm,rn clipu.b rn clipu.w rn
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 391 of 484 rej09b0051-0300 clip.b rn clip.w rn pipeline ????? slots instruction a if id ex next instruction if id ex ? ?? ? ? ?? ? ? ?? ? instruction after next if id ex ? ?? ? ? ?? ? ? ?? ? operation the pipeline ends after three stages: if, id, ex. in the ex stage, the data operation is completed via the alu. instruction issuance the exts.b, exts.w, extu.b, and extu.w instructions use the shifter. the other instructions do not cause resource contention. parallel execution capability with clip instructions, cs bit rewrite contention does not occur and parallel execution is possible.
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 392 of 484 rej09b0051-0300 (2) multiply-and-accumulate instruction instruction type mac.w @rm+,@rn+ pipeline ???????? slots instruction a if id ex ma ma mm mm next instruction if ? ? id ex ? ?? ? ? ?? ? ? ?? ? instruction after next if ? ? id ex ? ?? ? ? ?? ? ? ?? ? operation the pipeline ends after seven stages: if, id, ex, ma, ma, mm, mm. mm indicates a state in which the multiplier is operating. see section 8.7, contention due to multiplier, for general pipeline details. this instruction has three execution slots, a latency of five, and four lock states. detailed examples where there are consecutive instructions relating to the pipeline of this instruction or the multiplier are given below. (a) when a mac.w instruction is immediately followed by a mac.w or mac.l instruction there is no multiplier contention. ???????? slots mac.w @rm+,@rn+ if id ex ma ma mm mm mac.w @rm+,@rn+ if ? ? id ex ma ma mm mm instruction after next if ? ? ? id ex ? ?? ? ? ?? ? ? ?? ? (b) when a mac.w instruction is immediately followed by a muls.w, mulu.w, dmuls.w, dmulu.w, mul.l, mulr, sts (register). sts.l (memory), or lds (register) instruction as the mac.w instruction locks the multiplier, stalling occurs a further 2-slot interval back.
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 393 of 484 rej09b0051-0300 ???????? slots mac.w @rm+,@rn+ if id ex ma ma mm mm sts macl,rn if????idexwb instruction after next if ? ? ? id ex ? ?? ? ? ?? ? ? ?? ? (c) when a mac.w instruction is immediately followed by an lds.l (memory) instruction execution is delayed for a mac execution state (3-slot) interval. ???????? slots mac.w @rm+,@rn+ if id ex ma ma mm mm lds.l @rn+,macl if ? ? ? id ex ma wb instruction after next if ? ? id ex ? ?? ? ? ?? ? ? ?? ? instruction issuance this instruction uses the memory access pipeline. this instruction uses the multiplier. this instruction is executed even if the multiplier is locked. this instruction locks the multiplier for a 4-slot interval. parallel execution capability this is a multi-cycle instruction, and cannot be executed in parallel with a subsequent instruction. (see section 8.3.4, details of contention due to multi-cycle instruction.)
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 394 of 484 rej09b0051-0300 (3) double-precision multiply-and-accumulate instruction instruction type mac.l @rm+,@rn+ pipeline ???????? slots instruction a if id ex ma ma mm mm mm next instruction if ? ? ? id ex ? ?? ? ? ?? ? ? ?? ? instruction after next if ? ? ? id ex ? ?? ? ? ?? ? ? ?? ? operation the pipeline ends after eight stages: if, id, ex, ma, ma, mm, mm, mm. mm indicates a state in which the multiplier is operating. see section 8.7, contention due to multiplier, for general pipeline details. this instruction has four execution slots, a latency of six, and five lock states. detailed examples where there are consecutive instructions relating to the pipeline of this instruction or the multiplier are given below. (a) when a mac.l instruction is immediately followed by a mac.l or mac.w instruction there is no multiplier contention. ??????? slots mac.l @rm+,@rn+ if id ex ma ma mm mm mm mac.l @rm+,@rn+ if ? ? ? id ex ma ma mm mm mm instruction after next if ? ? ? ? ? id ex ? ?? ? ? ?? ? ? ?? ?
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 395 of 484 rej09b0051-0300 (b) when a mac.l instruction is immediately followed by a muls.w, mulu.w, dmuls.l, dmulu.l, mul.l, mulr, sts (register). sts.l (memory), or lds (register) instruction as the mac.l instruction locks the multiplier, stalling occurs a further 2 states back. ???????? slots mac.l @rm+,@rn+ if id ex ma ma mm mm mm stsmach,rn if?????idexwb instruction after next if ? ? ? ? id ex ? ?? ? ? ?? ? ? ?? ? (c) when a mac.l instruction is immediately followed by an lds.l (memory) instruction execution is delayed for a mac execution state (4-slot) interval. ???????? slots mac.l @rm+,@rn+ if id ex ma ma mm mm mm lds.l @rn+,macl if ? ? ? ? id ex ma wb instruction after next if ? ? ? id ex ? ?? ? ? ?? ? ? ?? ? instruction issuance this instruction uses the memory access pipeline. this instruction uses the multiplier. this instruction is executed even if the multiplier is locked. this instruction locks the multiplier for a 5-slot interval. parallel execution capability this is a multi-cycle instruction, and cannot be executed in parallel with a subsequent instruction. (see section 8.3.4, details of contention due to multi-cycle instruction.)
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 396 of 484 rej09b0051-0300 (4) multiply instructions instruction types muls.w rm,rn mulu.w rm,rn pipeline ????? slots instruction a if id mm mm next instruction if id ex ? ?? ? ? ?? ? ? ?? ? instruction after next if id ex ? ?? ? ? ?? ? ? ?? ? operation the pipeline ends after four stages: if, id, mm, mm. mm indicates a state in which the multiplier is operating. see section 8.7, contention due to multiplier, for general pipeline details. these instructions have one execution slot, a latency of two, and one lock state. detailed examples where there are consecutive instructions relating to the pipeline of this instruction or the multiplier are given below. (a) when a muls.w instruction is immediately followed by a mac.w or mac.l instruction there is no multiplier contention. ???????? slots muls.w if id mm mm mac.w if id ex ma ma mm mm instruction after next if ? id ex ? ?? ? ? ?? ? ? ?? ?
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 397 of 484 rej09b0051-0300 (b) when a muls.w instruction is immediately followed by a muls.w, mulu.w, dmuls.l, dmulu.l, mul.l, mulr, sts (register). sts.l (memory), or lds (register) instruction as the muls.w instruction locks the multiplier, parallel execution is not possible. ?????? slots muls.w rm,rn if id mm mm sts macl,rn if ? id ex wb instruction after next if id ex ? ?? ? ? ?? ? ? ?? ? (c) when a muls.w instruction is immediately followed by an lds.l (memory) instruction parallel execution with the muls.w instruction is not possible, as it locks the multiplier. ?????? slots muls.w rm,rn if id mm mm lds.l @rn+,macl if ? id ex ma wb instruction after next if id ex ? ?? ? ? ?? ? ? ?? ? instruction issuance these instructions use the multiplier. these instructions lock the multiplier for a 1-slot interval. parallel execution capability no particular comments
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 398 of 484 rej09b0051-0300 (5) double-precision multiply instructions instruction types dmuls.l rm,rn dmulu.l rm,rn mul.l rm,rn pipeline ????? slots instruction a if id mm mm mm next instruction if ? id ex ? ?? ? ? ?? ? ? ?? ? instruction after next if ? id ex ? ?? ? ? ?? ? ? ?? ? operation the pipeline ends after five stages: if, id, mm, mm, mm. mm indicates a state in which the multiplier is operating. see section 8.7, contention due to multiplier, for general pipeline details. these instructions have two execution slots, a latency of three, and two lock states. detailed examples where there are consecutive instructions relating to the pipeline of this instruction or the multiplier are given below. (a) when a mul.l instruction is immediately followed by a mac.w or mac.l instruction there is no multiplier contention. ???????? slots mul.l rm,rn if id mm mm mm mac.l @rm+,@rn+ if ? id ex ma ma mm mm mm instruction after next if ? ? ? id ex ? ?? ? ? ?? ? ? ?? ?
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 399 of 484 rej09b0051-0300 (b) when a mul.l instruction is immediately followed by a muls.w, mulu.w, dmuls.l, dmulu.l, mul.l, mulr, sts (register). sts.l (memory), or lds (register) instruction as the mul.l instruction locks the multiplier, stalling occurs a further 2-slot interval back. ???????? slots mul.l rm,rn if id mm mm mm sts macl,rn if??idexwb instruction after next if ? id ex ? ?? ? ? ?? ? ? ?? ? (c) when a mul.l instruction is immediately followed by an lds.l (memory) instruction execution is delayed during execution of mul.l (two cycles). ???????? slots mul.l if id mmmmmm lds.l @rn+,macl if ? ? id ex ma wb instruction after next if ? id ex ? ?? ? ? ?? ? ? ?? ? instruction issuance these instructions use the multiplier. these instructions lock the multiplier for a 2-slot interval. parallel execution capability these are multi-cycle instructions, and cannot be executed in parallel with a subsequent instruction. (see section 8.3.4, details of contention due to multi-cycle instruction.)
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 400 of 484 rej09b0051-0300 (6) double-precision multiply instruction (general register return) instruction type mulr r0,rn pipeline ??????? slots instruction a if id mm mm mm wb next instruction if ? id ex ? ?? ? ? ?? ? ? ?? ? instruction after next if id ex ? ?? ? ? ?? ? ? ?? ? operation the pipeline ends after six stages: if, id, mm, mm, mm, wb. mm indicates a state in which the multiplier is operating. see section 8.7, contention due to multiplier, for general pipeline details. this instruction has two execution slots, a latency of four, and two lock states. detailed examples where there are consecutive instructions relating to the pipeline of this instruction or the multiplier are given below. (a) when a mulr instruction is immediately followed by a mac.w or mac.l instruction there is no multiplier contention. ???????? slots mulr r0,rn if id mm mm mm wb mac.l @rm+,@rn+ if ? id ex ma ma mm mm mm instruction after next if ? ? ? id ex ? ?? ? ? ?? ? ? ?? ?
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 401 of 484 rej09b0051-0300 (b) when a mulr instruction is immediately followed by a muls.w, mulu.w, dmuls.l, dmulu.l, mul.l, mulr, sts (register). sts.l (memory), or lds (register) instruction as the mulr instruction locks the multiplier, stalling occurs a further 1-slot interval back. ???????? slots mulr r0,rn if id mm mm mm wb mulrr0,rn if ? ? id mmmmmmwb instruction after next if ? id ex ? ?? ? ? ?? ? ? ?? ? (c) when a mulr instruction is immediately followed by an sts (register) or sts.l (memory) instruction as the mulr instruction locks the multiplier, and multiplication result read path contention occurs, stalling occurs a further 2-slot interval back. ???????? slots mulr r0,rn if id mm mm mm wb sts macl,rn if ? ? ? id ex wb instruction after next if ? ? id ex ? ?? ? ? ?? ? ? ?? ? (d) when a mulr instruction is immediately followed by an lds.l (memory) instruction execution is delayed for a mulr instruction execution state (2-slot) interval. ???????? slots mulr r0,rn if id mm mm mm wb lds.l @rn+,macl if ? ? id ex ma wb instruction after next if ? id ex ? ?? ? ? ?? ? ? ?? ? instruction issuance this instruction uses the multiplier. this instruction locks the multiplier for a 2-slot interval. this instruction uses the multiplication result read path. parallel execution capability this is a multi-cycle instruction, and cannot be executed in parallel with a subsequent instruction. (see section 8.3.4, details of contention due to multi-cycle instruction.)
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 402 of 484 rej09b0051-0300 (7) divu instruction instruction type divu r0,rn pipeline ??????? slots instruction a if id ex ? ?? ? ? ?? ? ? ?? ? ex ex next instruction if ? ? ? id ex ? ?? ? ? ?? ? ? ?? ? instruction after next if ? ? ? id ex ? ?? ? ? ?? ? ? ?? ? operation the pipeline ends after 36 stages: if, id, ex, ex, ex, ex, ex, ex, ex, ex, ex, ex, ex, ex, ex, ex, ex, ex, ex, ex, ex, ex, ex, ex, ex, ex, ex, ex, ex, ex, ex, ex, ex, ex, ex, ex. data operations are completed using the alu in the ex stages. instruction issuance this instruction uses the shift pipeline. parallel execution capability this is a multi-cycle instruction, and cannot be executed in parallel with a subsequent instruction.
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 403 of 484 rej09b0051-0300 (8) divs instruction instruction type divs r0,rn pipeline ??????? slots instruction a if id ex ? ?? ? ? ?? ? ? ?? ? ex ex next instruction if ? ? ? id ex ? ?? ? ? ?? ? ? ?? ? instruction after next if ? ? ? id ex ? ?? ? ? ?? ? ? ?? ? operation the pipeline ends after 38 stages: if, id, ex, ex, ex, ex, ex, ex, ex, ex, ex, ex, ex, ex, ex, ex, ex, ex, ex, ex, ex, ex, ex, ex, ex, ex, ex, ex, ex, ex, ex, ex, ex, ex, ex, ex, ex, ex. data operations are completed using the alu in the ex stages. instruction issuance this instruction do not cause resource contention. parallel execution capability this is a multi-cycle instruction, and cannot be executed in parallel with a subsequent instruction.
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 404 of 484 rej09b0051-0300 8.9.3 logical operation instructions (1) register-register logical operation instructions instruction types and rm,rn and #imm,r0 not rm,rn or rm,rn or #imm,r0 tst rm,rn tst #imm,r0 xor rm,rn xor #imm,r0 pipeline ????? slots instruction a if id ex next instruction if id ex ? ?? ? ? ?? ? ? ?? ? instruction after next if id ex ? ?? ? ? ?? ? ? ?? ? operation the pipeline ends after three stages: if, id, ex. in the ex stage, the data operation is completed via the alu. instruction issuance these instructions do not cause resource contention. parallel execution capability no particular comments
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 405 of 484 rej09b0051-0300 (2) memory logical operation instructions instruction types and.b #imm,@(r0,gbr) or.b #imm,@(r0,gbr) xor.b #imm,@(r0,gbr) pipeline ?????? slots instruction a if id ex ma ex ma next instruction if ? ? id ex ? ?? ? ? ?? ? ? ?? ? instruction after next if ? ? id ex ? ?? ? ? ?? ? ? ?? ? operation the pipeline ends after six stages: if, id, ex, ma, ex, ma. instruction issuance these instructions use the memory access pipeline. parallel execution capability these are multi-cycle instructions, and cannot be executed in parallel with a subsequent instruction. (see section 8.3.4, details of contention due to multi-cycle instruction.)
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 406 of 484 rej09b0051-0300 (3) memory logical operation instructions instruction type tst.b #imm,@(r0,gbr) pipeline ????? slots instruction a if id ex ma ex next instruction if ? ? id ex ? ?? ? ? ?? ? ? ?? ? instruction after next if ? ? id ex ? ?? ? ? ?? ? ? ?? ? operation the pipeline ends after five stages: if, id, ex, ma, ex. instruction issuance this instruction uses the memory access pipeline. parallel execution capability this is a multi-cycle instruction, and cannot be executed in parallel with a subsequent instruction. (see section 8.3.4, details of contention due to multi-cycle instruction.)
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 407 of 484 rej09b0051-0300 (4) tas instruction instruction type tas.b @rn pipeline ?????? slots instruction a if id ex ma ex ma next instruction if ? ? id ex ? ?? ? ? ?? ? ? ?? ? instruction after next if ? ? id ex ? ?? ? ? ?? ? ? ?? ? operation the pipeline ends after six stages: if, id, ex, ma, ex, ma. instruction issuance this instruction uses the memory access pipeline. parallel execution capability this is a multi-cycle instruction, and cannot be executed in parallel with a subsequent instruction.
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 408 of 484 rej09b0051-0300 (5) register-register bit operation instructions instruction types bld #imm3,rn bset #imm3,rn bclr #imm3,rn bst #imm3,rn pipeline ????? slots instruction a if id ex next instruction if id ex ? ?? ? ? ?? ? ? ?? ? instruction after next if id ex ? ?? ? ? ?? ? ? ?? ? operation the pipeline ends after three stages: if, id, ex. in the ex stage, the data operation is completed via the alu. instruction issuance these instructions do not cause resource contention. parallel execution capability no particular comments
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 409 of 484 rej09b0051-0300 (6) memory-tbit logical operation instructions instruction types band.b #imm3,@(disp12,rn) bandnot.b #imm3,@(disp12,rn) bld.b #imm3,@(disp12,rn) bldnot.b #imm3,@(disp12,rn) bor.b #imm3,@(disp12,rn) bornot.b #imm3,@(disp12,rn) bxor.b #imm3,@(disp12,rn) pipeline ?????? slots instruction a if id ex ma ex next instruction if ? id ex ? ?? ? ? ?? ? ? ?? ? instruction after next if ? ? id ex ? ?? ? ? ?? ? ? ?? ? operation the pipeline ends after five stages: if, id, ex, ma, ex. instruction issuance these instructions use the memory access pipeline. parallel execution capability these are 32-bit instructions, and cannot be used in parallel execution. if the instruction following this instruction is band.b, bandnot.b, bld.b, bldnot.b, bor.b, bornot.b, or bxor, the final step is executed in parallel with the instruction that follows. parallel execution with the final step is not possible with any other instruction. (see section 8.3.5, details of contention due to 32-bit instruction).
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 410 of 484 rej09b0051-0300 ?????? slots band.b #imm,@(disp12,rn) if id ex ma ex bor.b #imm,@(disp12,rn) if ? id ex ? ?? ? ? ?? ? ? ?? ? bandnot.b #imm,@(disp12,rn) if ? ? id ex ? ?? ? ? ?? ? ? ?? ? ?????? slots band.b #imm,@(disp12,rn) if id ex ma ex add rm,rn if??idex ? ?? ? ? ?? ? ? ?? ? instruction after next if ? ? id ex ? ?? ? ? ?? ? ? ?? ? ?????? slots band.b #imm,@(disp12,rn) if id ex ma ex rotcl if??idex band.b #imm,@(disp12,rn) if ? ? id ex instruction after next if ? ? ? ?
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 411 of 484 rej09b0051-0300 (7) memory bit operation instructions instruction types bclr.b #imm3,@(disp12,rn) bset.b #imm3,@(disp12,rn) bst.b #imm3,@(disp12,rn) pipeline ?????? slots instruction a if id ex ma ex ma next instruction if ? ? id ex ? ?? ? ? ?? ? ? ?? ? instruction after next if ? ? ? id ex ? ?? ? ? ?? ? ? ?? ? operation the pipeline ends after six stages: if, id, ex, ma, ex, ma. instruction issuance these instructions use the memory access pipeline. parallel execution capability these are 32-bit instructions, and cannot be used in parallel execution. (see section 8.3.5, details of contention due to 32-bit instruction.)
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 412 of 484 rej09b0051-0300 8.9.4 shift instructions instruction types rotl rn rotr rn rotcl rn rotcr rn shal rn shar rn shll rn shlr rn shll2 rn shlr2 rn shll8 rn shlr8 rn shll16 rn shlr16 rn shad rm,rn shld rm,rn pipeline ????? slots instruction a if id ex next instruction if id ex ? ?? ? ? ?? ? ? ?? ? instruction after next if id ex ? ?? ? ? ?? ? ? ?? ? operation the pipeline ends after three stages: if, id, ex. in the ex stage, the data operation is completed via the shifter. instruction issuance these instructions use the shift pipeline.
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 413 of 484 rej09b0051-0300 parallel execution capability no particular comments
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 414 of 484 rej09b0051-0300 8.9.5 branch instructions (1) conditional branch instructions instruction types bf label bt label pipeline (a) when condition is met ????? slots instruction a if id ex next instruction if ? ? ?? ? ? ?? ? ? ?? ? (fetched but discarded) instruction after next if ? ?? ? ? ?? ? ? ?? ? (fetched but discarded) second instruction after next if ? ?? ? ? ?? ? ? ?? ? (fetched but discarded) branch destination instruction ?ifidex ? ?? ? ? ?? ? ? ?? ? (b) when condition is not met ????? slots instruction a if id ex next instruction if id ex instruction after next if id ex ? ?? ? ? ?? ? ? ?? ? second instruction after next ??? operation the pipeline ends after three stages: if, id, ex. condition determination is performed in the id stage. conditional branch instructions are not delayed branch instructions.
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 415 of 484 rej09b0051-0300 (a) when condition is met the branch destination address is calculated in the ex stage. all overrun-fetched instructions up to that point are discarded. the branch destination instruction fetch is started from the slot following the instruction a ex stage slot. (b) when condition is not met if it is determined in the id stage that the condition is not met, processing proceeds with nothing done in the ex stage. the next instruction is fetched and executed. a typical pipeline is shown below. if the preceding instruction is a cmp instruction, execution is delayed by 1 cycle. ????? slots cmp if id ex bf if ? id ex branch destination if if the preceding instruction is a single-precision fcmp instruction, execution is delayed by 2 cycles. ?????? slots fcmp/single if df e1 e2 bf if ? ? id ex branch destination if if the preceding instruction is a double-precision fcmp instruction, execution is delayed by 3 cycles. ??????? slots fcmp/double if df e1 e1 e2 bf if???idex branch destination if instruction issuance these instructions use the branch pipeline. parallel execution capability no particular comments
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 416 of 484 rej09b0051-0300 (2) delayed conditional branch instructions instruction types bf/s label bt/s label pipeline (a) when condition is met ????? slots instruction a if id ex delay slot if ? ? id ex ? ?? ? ? ?? ? ? ?? ? instruction after next if ? ?? ? ? ?? ? ? ?? ? (fetched but discarded) second instruction after next if ? ?? ? ? ?? ? ? ?? ? (fetched but discarded) branch destination instruction ?ifidex ? ?? ? ? ?? ? ? ?? ? (b) when condition is not met ????? slots instruction a if id ex next instruction if id ex instruction after next if id ex ? ?? ? ? ?? ? ? ?? ? second instruction after next if id ex ? ?? ? ? ?? ? ? ?? ? operation the pipeline ends after three stages: if, id, ex. condition determination is performed in the id stage. interrupts are not accepted in the delay slot. (a) when condition is met the branch destination address is calculated in the ex stage. all overrun-fetched instructions up to that point are discarded. the branch destination instruction fetch is started from the slot following the instruction a ex stage slot.
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 417 of 484 rej09b0051-0300 (b) when condition is not met if it is determined in the id stage that the condition is not met, processing proceeds with nothing done in the ex stage. the next instruction is fetched and executed. a typical pipeline is shown below. if the preceding instruction is a cmp instruction, execution is delayed by 1 cycle. ????? slots cmp if id ex bf/s if ? id ex delay slot if ? ? id if the preceding instruction is a single-precision fcmp instruction, execution is delayed by 2 cycles. ?????? slots fcmp/single if df e1 e2 bf/s if ? ? id ex delay slot if ? ? ? id if the preceding instruction is a double-precision fcmp instruction, execution is delayed by 3 cycles. ??????? slots fcmp/double if df e1 e1 e2 bf/s if ? ? ? id ex delay slot if????id instruction issuance these instructions use the branch pipeline. if an instruction fetch has not yet been performed for the instruction (delay slot) immediately following one of these instructions, execution of that instruction is delayed. parallel execution capability no particular comments
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 418 of 484 rej09b0051-0300 (3) unconditional branch instructions instruction types bra label braf rm bsr label bsrf rm jmp @rm jsr @rm rts pipeline ????? slots instruction a if id ex delay slot if ? ? id ex ? ?? ? ? ?? ? ? ?? ? instruction after next if ? ?? ? ? ?? ? ? ?? ? (fetched but discarded) second instruction after next if ? ?? ? ? ?? ? ? ?? ? (fetched but discarded) branch destination instruction ?ifidex ? ?? ? ? ?? ? ? ?? ? operation the pipeline ends after three stages: if, id, ex. unconditional branch instructions are delayed branch instructions. the branch destination address is calculated in the ex stage. the instruction after the unconditional branch instruction (instruction a) ? that is, the delay slot instruction ? is not discarded after being fetched, as with a conditional branch instruction, but is executed. however, the id stage of this delay slot instruction is stalled for a 2-slot interval. the branch destination instruction fetch is started from the slot following the instruction a ex stage slot. interrupts are not accepted in the delay slot. instruction issuance these instructions use the branch pipeline. if an instruction fetch has not yet been performed for the instruction (delay slot) immediately following one of these instructions, execution of that instruction is delayed.
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 419 of 484 rej09b0051-0300 parallel execution capability no particular comments
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 420 of 484 rej09b0051-0300 (4) no delay unconditional branch instructions instruction types jsr/n @rm rts/n rtv/n rm pipeline ????? slots instruction a if id ex next instruction if ? ? ?? ? ? ?? ? ? ?? ? (fetched but discarded) instruction after next if ? ?? ? ? ?? ? ? ?? ? (fetched but discarded) second instruction after next if ? ?? ? ? ?? ? ? ?? ? (fetched but discarded) branch destination instruction ?ifidex ? ?? ? ? ?? ? ? ?? ? operation the pipeline ends after three stages: if, id, ex. condition determination is performed in the id stage. conditional branch instructions are not delayed branch instructions. the branch destination address is calculated in the ex stage. all overrun-fetched instructions up to that point are discarded. the branch destination instruction fetch is started from the slot following the instruction a ex stage slot. instruction issuance these instructions use the branch pipeline. parallel execution capability no particular comments
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 421 of 484 rej09b0051-0300 (5) unconditional branch instructions with no delay (jsr/n @@(disp,tbr)) instruction types jsr/n @@(disp,tbr) pipeline ????? slots instruction a if id ex ma ex next instruction if ? ? ?? ? ? ?? ? ? ?? ? (fetched but discarded) instruction after next if ? ?? ? ? ?? ? ? ?? ? (fetched but discarded) second instruction after next if ? ?? ? ? ?? ? ? ?? ? (fetched but discarded) branch destination instruction ? ? ? if id ex ? ?? ? ? ?? ? ? ?? ? operation the pipeline ends after five stages: if, id, ex, ma, ex. condition determination is performed in the id stage. this is not a delayed branch instruction. the branch destination address is calculated in the second ex stage. all overrun-fetched instructions up to that point are discarded. the branch destination instruction fetch is started from the slot following the slot with the second ex of instruction a. instruction issuance this instruction uses the branch pipeline. this instruction uses the memory access pipeline. parallel execution capability no particular comments
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 422 of 484 rej09b0051-0300 8.9.6 system control instructions (1) system control alu instructions instruction types clrt ldc rm,gbr ldc rm,tbr ldc rm,vbr lds rm,pr nop sett stc gbr,rn stc tbr,rn stc vbr,rn sts pr,rn nott pipeline ????? slots instruction a if id ex next instruction if id ex ? ?? ? ? ?? ? ? ?? ? instruction after next if id ex ? ?? ? ? ?? ? ? ?? ? operation the pipeline ends after three stages: if, id, ex. in the ex stage, the data operation is completed via the alu. instruction issuance these instructions do not cause resource contention. parallel execution capability no particular comments
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 423 of 484 rej09b0051-0300 (2) system control alu instruction instruction type ldc rm,sr pipeline ??????? slots instruction a if id ex ex ex next instruction if ? ? id ex ? ?? ? ? ?? ? ? ?? ? instruction after next if ? ? id ex ? ?? ? ? ?? ? ? ?? ? operation the pipeline ends after five stages: if, id, ex, ex, ex. in the first ex stage, the data operation is completed via the alu. instruction issuance this instruction does not cause resource contention. parallel execution capability this is a multi-cycle instruction, and cannot be executed in parallel with a subsequent instruction.
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 424 of 484 rej09b0051-0300 (3) system control alu instruction instruction type stc sr,rn pipeline ??????? slots instruction a if id ex ex next instruction if ? id ex ? ?? ? ? ?? ? ? ?? ? instruction after next if ? id ex ? ?? ? ? ?? ? ? ?? ? operation the pipeline ends after four stages: if, id, ex, ex. in the second ex stage, the data operation is completed via the alu. instruction issuance no particular comments a typical pipeline when performing a cs bit read is shown below. ??????? slots clip if id ex stc if ? id ex ex next instruction if ? id ex ? ?? ? ? ?? ? ? ?? ? instruction after next if ? id ex ? ?? ? ? ?? ? ? ?? ? parallel execution capability this is a multi-cycle instruction, and cannot be executed in parallel with a subsequent instruction.
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 425 of 484 rej09b0051-0300 (4) ldc.l and lds.l instructions instruction types ldc.l @rm+,gbr ldc.l @rm+,vbr lds.l @rm+,pr pipeline ??????? slots instruction a if id ex ma wb next instruction if id ex ? ?? ? ? ?? ? ? ?? ? instruction after next if id ex ? ?? ? ? ?? ? ? ?? ? operation the pipeline ends after five stages: if, id, ex, ma, wb. instruction issuance these instructions use the memory access pipeline. parallel execution capability no particular comments
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 426 of 484 rej09b0051-0300 (5) ldc.l instruction instruction type ldc.l @rm+,sr pipeline ??????? slots instruction a if id ex ma ex ex ex next instruction if ? ? ? ? id ex ? ?? ? ? ?? ? ? ?? ? instruction after next if ? ? ? ? id ex ? ?? ? ? ?? ? ? ?? ? operation the pipeline ends after seven stages: if, id, ex, ma, ex, ex, ex. instruction issuance this instruction uses the memory access pipeline. parallel execution capability this is a multi-cycle instruction, and cannot be executed in parallel with a subsequent instruction.
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 427 of 484 rej09b0051-0300 (6) stc.l instructions instruction types stc.l gbr,@-rn stc.l vbr,@-rn sts.l pr,@-rn pipeline ??????? slots instruction a if id ex ma next instruction if id ex ? ?? ? ? ?? ? ? ?? ? instruction after next if id ex ? ?? ? ? ?? ? ? ?? ? operation the pipeline ends after four stages: if, id, ex, ma. instruction issuance these instructions use the memory access pipeline. parallel execution capability no particular comments
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 428 of 484 rej09b0051-0300 (7) stc.l instruction instruction type stc.l sr, @-rn pipeline ??????? slots instruction a if id ex ex ma next instruction if ? id ex ? ?? ? ? ?? ? ? ?? ? instruction after next if ? id ex ? ?? ? ? ?? ? ? ?? ? operation the pipeline ends after five stages: if, id, ex, ex, ma. instruction issuance this instruction uses the memory access pipeline. parallel execution capability this is a multi-cycle instruction, and cannot be executed in parallel with a subsequent instruction. although this instruction uses the memory access pipeline, parallel execution is possible if the preceding instruction is a single-cycle memory access instruction.
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 429 of 484 rej09b0051-0300 (8) register mac transfer instructions instruction types clrmac lds rm,mach lds rm,macl pipeline ??????? slots instruction a if id mm mm next instruction if id ex ? ?? ? ? ?? ? ? ?? ? instruction after next if id ex ? ?? ? ? ?? ? ? ?? ? operation the pipeline ends after four stages: if, id, mm, mm. mm indicates a state in which the multiplier is operating. see section 8.7, contention due to multiplier, for general pipeline details. these instructions have one execution slot, a latency of two, and one lock state. detailed examples where there are consecutive instructions relating to the pipeline of this instruction or the multiplier are given below. (a) when a clrmac instruction is immediately followed by a mac.w or mac.l instruction there is no multiplier contention. ???????? slots clrmac if id mm mm mac.w @rm+,@rn+ if id ex ma ma mm mm instruction after next if ? ? id ex ? ?? ? ? ?? ? ? ?? ?
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 430 of 484 rej09b0051-0300 (b) when a clrmac instruction is immediately followed by a muls.w, mulu.w, dmuls.l, dmulu.l, mul.l, mulr, sts (register). sts.l (memory), or lds (register) instruction parallel execution with the clrmac instruction is not possible, as it locks the multiplier. ???????? slots clrmac if id mm mm sts macl,rn if ? id ex wb instruction after next if id ex ? ?? ? ? ?? ? ? ?? ? (c) when a clrmac instruction is immediately followed by an lds.l (memory) instruction execution is delayed for a clrmac instruction execution state (1-slot) interval. ???????? slots clrmac if id mm mm lds.l @rn+,macl if ? id ex ma wb instruction after next if id ex ? ?? ? ? ?? ? ? ?? ? instruction issuance these instructions use the multiplier. these instructions lock the multiplier for a 1-slot interval. parallel execution capability no particular comments
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 431 of 484 rej09b0051-0300 (9) memory mac transfer instructions instruction types lds.l @rm+,mach lds.l @rm+,macl pipeline ????? slots instruction a if id ex ma wb next instruction if id ex ? ?? ? ? ?? ? ? ?? ? instruction after next if id ex ? ?? ? ? ?? ? ? ?? ? operation the pipeline ends after five stages: if, id, ex, ma, wb. see section 8.7, contention due to multiplier, for general pipeline details. this instruction has one execution slot, a latency of three, and two lock states. detailed examples where there are consecutive instructions relating to the pipeline of this instruction or the multiplier are given below. (a) when an lds.l instruction is immediately followed by a mac.w or mac.l instruction there is no multiplier contention, but there is memory access contention, with 1-cycle stalling. ???????? slots lds.l @rm+,mach if id ex ma wb mac.w @rm+,@rn+ if ? id ex ma ma mm mm instruction after next if ? ? id ex ? ?? ? ? ?? ? ? ?? ?
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 432 of 484 rej09b0051-0300 (b) when an lds.l instruction is immediately followed by a muls.w, mulu.w, dmuls.l, dmulu.l, mul.l, mulr, sts (register). sts.l (memory), or lds (register) instruction as the lds.l instruction locks the multiplier, stalling occurs a further 1-slot interval back. ?????? slots lds.l @rm+,mach if id ex ma wb sts macl,rn if??idexwb instruction after next if ? id ex ? ?? ? ? ?? ? ? ?? ? (c) when an lds.l instruction is immediately followed by an lds.l (memory) instruction execution is delayed for an lds.l instruction execution state (1-slot) interval. ????? slots lds.l @rn+,mach if id ex ma wb lds.l @rn+,macl if ? id ex ma wb instruction after next if id ex ? ?? ? ? ?? ? ? ?? ? instruction issuance these instructions use the memory access pipeline. these instructions use the multiplier. these instructions are executed if there is a remaining multiplication lock interval of 1. these instructions lock the multiplier for a 2-slot interval. parallel execution capability no particular comments
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 433 of 484 rej09b0051-0300 (10) mac register transfer instructions instruction types sts mach,rn sts macl,rn pipeline ????? slots instruction a if id ex wb next instruction if id ex ? ?? ? ? ?? ? ? ?? ? instruction after next if id ex ? ?? ? ? ?? ? ? ?? ? operation the pipeline ends after four stages: if, id, ex, wb. see section 8.7, contention due to multiplier, for general pipeline details. these instructions have one execution slot, a latency of two, and zero lock state. detailed examples where there are consecutive instructions relating to the pipeline of this instruction or the multiplier are given below. (a) when an sts instruction is immediately followed by a mac.w or mac.l instruction there is no multiplier contention. ??????? slots sts mach,rn if id ex wb mac.w @rm+,@rn+ if id ex ma ma mm mm instruction after next if ? id ex ? ?? ? ? ?? ? ? ?? ?
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 434 of 484 rej09b0051-0300 (b) when an sts instruction is immediately followed by a muls.w, mulu.w, dmuls.l, dmulu.l, mul.l, mulr, sts (register). sts.l (memory), or lds (register) instruction as the sts instruction does not lock the multiplier, parallel execution is performed. ??????? slots sts mach,rn if id mm mm wb mul.l rm,rn if id mm mm mm instruction after next if id ex ? ?? ? ? ?? ? ? ?? ? (c) when an sts instruction is immediately followed by a sts (register) or sts.l (memory) instruction. parallel execution is not possible, as contention occurs with the multiplication result read bus. ??????? slots sts mach,rn if id ex wb sts macl,rn if ? id ex wb instruction after next if id ex ? ?? ? ? ?? ? ? ?? ? (d) when an sts instruction is immediately followed by an lds.l (memory) instruction parallel execution is performed. there is no multiplier contention. ??????? slots sts mach,rn if id ex wb lds.l @rn+,macl if id ex ma wb instruction after next if id ex ? ?? ? ? ?? ? ? ?? ? instruction issuance these instructions use the multiplier, but do not lock it. these instructions use the multiplication result read path. parallel execution capability no particular comments
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 435 of 484 rej09b0051-0300 (11) mac memory transfer instructions instruction types sts.l mach,@-rn sts.l macl,@-rn pipeline ????? slots instruction a if id ex ma next instruction if id ex ? ?? ? ? ?? ? ? ?? ? instruction after next if id ex ? ?? ? ? ?? ? ? ?? ? operation the pipeline ends after four stages: if, id, ex, ma. see section 8.7, contention due to multiplier, for general pipeline details. these instructions have one execution slot, a latency of two, and zero lock state. detailed examples where there are consecutive instructions relating to the pipeline of this instruction or the multiplier are given below. (a) when an sts.l instruction is immediately followed by a mac.w or mac.l instruction there is no multiplier contention, but there is memory access contention, with 1-cycle stalling. ??????? slots sts.l mach,@-rn if id ex ma mac.w @rm+,@rn+ if ? id ex ma ma mm mm instruction after next if ? ? id ex ? ?? ? ? ?? ? ? ?? ?
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 436 of 484 rej09b0051-0300 (b) when an sts.l instruction is immediately followed by a muls.w, mulu.w, dmuls.l, dmulu.l, mul.l, mulr, sts (register). sts.l (memory), or lds (register) instruction as the sts.l instruction does not lock the multiplier, parallel execution is performed. ??????? slots sts.l macl,@-rn if id ex ma mul.l rm,rn if id mm mm instruction after next if id ex ? ?? ? ? ?? ? ? ?? ? (c) when an sts.l instruction is immediately followed by a sts (register) or sts.l (memory) instruction. parallel execution is not possible, as contention occurs with the multiplication result read bus. ??????? slots sts.l mach,@-rn if id ex ma sts.l macl,@-rn if ? id ex ma instruction after next if id ex ? ?? ? ? ?? ? ? ?? ? (d) when an sts.l instruction is immediately followed by an lds.l (memory) instruction memory access pipeline contention occurs and parallel execution is not possible. ??????? slots sts.l mach,@-rn if id ex ma lds.l @rn+,macl if ? id ex ma wb instruction after next if id ex ? ?? ? ? ?? ? ? ?? ? instruction issuance these instructions use the memory access pipeline. these instructions use the multiplier, but do not lock it. these instructions use the multiplication result read path. parallel execution capability no particular comments
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 437 of 484 rej09b0051-0300 (12) rte instruction instruction type rte pipeline ????????? slots instruction a if id ex ma ma ex ex ex delay slot if?????idex ? ?? ? ? ?? ? ? ?? ? branch destination if ? id ex ? ?? ? ? ?? ? ? ?? ? operation the pipeline ends after eight stages: if, id, ex, ma, ma, ex, ex, ex. rte is a delayed branch instruction. the id stage of the delay slot instruction is stalled for a 5-slot interval. the if stage of the branch destination instruction is started from the slot after the second ma stage of rte. instruction issuance this instruction does not cause resource contention. parallel execution capability this is a multi-cycle instruction, and cannot be executed in parallel with a subsequent instruction.
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 438 of 484 rej09b0051-0300 (13) resbank instruction instruction type resbank pipeline ? when b0 == 0 ??????????? slots instruction a if id exexexexexexexexex next instruction if????????idex ? ?? ? ? ?? ? ? ?? ? ? when b0 == 1 ?????? ? ?? ? ? ?? ? ? ?? ? ??? slots instruction a if id ex ma ma ma ? ?? ? ? ?? ? ? ?? ? ma ma ma wb next instruction if ? ? ? ? ? ? ?? ? ? ?? ? ? ?? ? id ex ? ?? ? ? ?? ? ? ?? ? operation the operation is different when the bo bit is 0 and when the bo bit is 1. when the bo bit is 0, restoration from a bank is performed. the pipeline comprises if and id followed by ex, ex, ex, ex, ex, ex, ex (nine repetitions of ex), and ends after 11 stages. during this time, register restoration from the bank is performed. when the bo bit is 1, restoration from the stack is performed. the pipeline comprises if, id, and ex, followed by ma, ma, ma, ma, ma, ma, ma, ma, ma, ma, ma, ma, ma, ma, ma, ma, ma, ma, ma, (19 repetitions of ma), followed by wb, and ends after 23 stages. instruction issuance when the bo bit is 0, this instruction does not cause resource contention. when the bo bit is 1, this instruction uses the memory access pipeline. parallel execution capability this is a multi-cycle instruction, and cannot be executed in parallel with a subsequent instruction. (see section 8.3.4, details of contention due to multi-cycle instruction.)
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 439 of 484 rej09b0051-0300 (14) ldbank instruction instruction type ldbank @rm,r0 pipeline ???????? slots instruction a if id exexexexexex next instruction if ? ? ? ? ? id ex ? ?? ? ? ?? ? ? ?? ? instruction after next if ? ? ? ? ? id ex ? ?? ? ? ?? ? ? ?? ? operation the pipeline ends after eight stages: if, id, ex, ex, ex, ex, ex, ex. instruction issuance this instruction does not cause resource contention. parallel execution capability this is a multi-cycle instruction, and cannot be executed in parallel with a subsequent instruction. (see section 8.3.4, details of contention due to multi-cycle instruction.)
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 440 of 484 rej09b0051-0300 (15) stbank instruction instruction type stbank r0,@rn pipeline ????????? slots instruction a if id exexexexexexex next instruction if ? ? ? ? ? ? id ex ? ?? ? ? ?? ? ? ?? ? instruction after next if ? ? ? ? ? ? id ex ? ?? ? ? ?? ? ? ?? ? operation the pipeline ends after nine stages: if, id, ex, ex, ex, ex, ex, ex, ex. instruction issuance this instruction does not cause resource contention. parallel execution capability this is a multi-cycle instruction, and cannot be executed in parallel with a subsequent instruction. (see section 8.3.4, details of contention due to multi-cycle instruction.)
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 441 of 484 rej09b0051-0300 (16) trap instruction instruction type trapa #imm pipeline ???????? slots instruction a if id ex ex ex ma ma ma next instruction if ? ? ?? ? ? ?? ? ? ?? ? instruction after next if ? ? ?? ? ? ?? ? ? ?? ? branch destination if operation the pipeline ends after eight stages: if, id, ex, ex, ex, ma, ma, ma. a trap instruction is not a delayed branch instruction. the if stage of the branch destination instruction is started from the slot containing the third ma of the trap instruction. instruction i s suance this instruction uses the memory access pipeline. parallel execution capability this is a multi-cycle instruction, and cannot be executed in parallel with a subsequent instruction.
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 442 of 484 rej09b0051-0300 (17) sleep instruction instruction type sleep pipeline ??????? slots sleep if id ex ? ?? ? ? ?? ? ? ?? ? ex ex next instruction if ? ? ?? ? ? ?? ? ? ?? ? instruction after next if ? ? ?? ? ? ?? ? ? ?? ? operation the pipeline ends after seven stages: if, id, ex, ma, ex, ex, ex. after a sleep instruction is executed, sleep mode or standby mode is entered. instruction issuance this instruction uses the memory access pipeline. parallel execution capability this is a multi-cycle instruction, and cannot be executed in parallel with a subsequent instruction.
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 443 of 484 rej09b0051-0300 8.9.7 exception handling (1) interrupt exception handling instruction type interrupt exception handling pipeline ? no banking ???????? slots interrupt if id ex ex ma ma ma next instruction if ? ?? ? ? ?? ? ? ?? ? instruction after next if ? ?? ? ? ?? ? ? ?? ? branch destination if id ? banking, no overflow ???????? slots interrupt if id ex ex ma ma ma ma next instruction if ? ?? ? ? ?? ? ? ?? ? branch destination if id ? banking and overflow ????????? slots interrupt if id ex ex ma ma ma ? ?? ? ? ?? ? ? ?? ? ma next instruction if ? ?? ? ? ?? ? ? ?? ? branch destination if ? ?? ? ? ?? ? ? ?? ? id operation an interrupt is accepted in the id stage of an instruction, and processing from that id stage onward is replaced by an exception handling sequence. interrupt handling operations are different when there is no banking, when there is banking, and when there is banking and overflow. when there is no banking, the pipeline ends after seven stages: if, id, ex, ex, ma, ma, ma.
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 444 of 484 rej09b0051-0300 when there is banking and no overflow, saving to the bank is performed automatically. the pipeline ends after eight stages: if, id, ex, ex, ma, ma, ma, ex. when there is banking and overflow, registers saved to the bank are automatically restored, and the bo bit is set to 1. the pipeline ends after 27 stages: if, id, ex, ex, ma, ma, ma, ex, ma, ma, ma, ma, ma, ma, ma, ma, ma, ma, ma, ma, ma, ma, ma, ma, ma, ma, ma. after the first two stages there are two repetitions of ex, three repetitions of ma, one ex, and 19 repetitions of ma. interrupt exception handling is not a delayed branch. the if stage of the branch destination instruction is started from the slot containing the third ma stage of the interrupt exception handling. interrupt sources comprise external interrupt request pins such as nmi, a user break, and interrupts by on-chip peripheral modules. interrupt acceptance interrupt exception handling is not accepted in a delay slot. if a multi-cycle instruction is currently being executed, interrupt exception handling is not accepted until after execution of that instruction is completed. however, a divu or divs instruction can be canceled during execution, allowing the interrupt to be accepted.
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 445 of 484 rej09b0051-0300 (2) address error exception handling instruction type address error exception handling pipeline ??????? slots address error exception handling if id ex ex ma ma ma next instruction if ? ?? ? ? ?? ? ? ?? ? instruction after next if ? ?? ? ? ?? ? ? ?? ? branch destination if id operation an address error is accepted in the id stage of an instruction, and processing from that id stage onward is replaced by the address error exception handling sequence. the pipeline ends after seven stages: if, id, ex, ex, ma, ma, ma. address error exception handling is not a delayed branch. the if stage of the branch destination instruction is started from the slot containing the last ma stage of the address error exception handling. address error generation sources comprise those related to an instruction fetch, and those related to a data read or write. see the hardware manual for details of generation sources. address error exception handling acceptance address error exception handling is not accepted in a delay slot. if a multi-cycle instruction is currently being executed, address error exception handling is not accepted until after execution of that instruction is completed. however, a divu or divs instruction can be canceled during execution, allowing address error exception handling to be accepted.
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 446 of 484 rej09b0051-0300 (3) illegal instruction exception handling instruction type illegal instruction exception handling pipeline ?????????? slots illegal instruction if id ex ex ma ma ma next instruction if ? ? ?? ? ? ?? ? ? ?? ? instruction after next if ? ? ?? ? ? ?? ? ? ?? ? branch destination if id operation an illegal instruction is accepted in the id stage of an instruction, and processing from that id stage onward is replaced by the illegal instruction exception handling sequence. the pipeline ends after seven stages: if, id, ex, ex, ma, ma, ma. illegal instruction exception handling is not a delayed branch. address error generation sources comprise those related to general illegal instructions and those related to slot illegal instructions. when undefined code located other than in the slot immediately after a delayed branch instruction (called the delay slot) is decoded, general illegal instruction exception handling is performed. when undefined core located in the delay slot is decoded, or an instruction that modifies the program counter, and a 32-bit instruction, and a resbank instruction, and a divu or divs instruction are located in the delay slot and decoded, slot illegal instruction handling is performed. general illegal instruction exception handling is also performed if an fpu instruction or fpu- related cpu instruction is executed while the fpu is in the module stopped state. the if stage of the branch destination instruction is started from the slot containing the last ma stage of the illegal instruction exception handling.
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 447 of 484 rej09b0051-0300 (4) fpu exception handling instruction type fpu exception handling pipeline ??????? slots fpu exception handling if id ex ex ma ma ma next instruction if ? ?? ? ? ?? ? ? ?? ? instruction after next if ? ?? ? ? ?? ? ? ?? ? branch destination if id operat i on an fpu execution is accepted in the id stage of an instruction, and processing from that id stage onward is replaced by the fpu exception handling sequence. the pipeline ends after six stages: if, id, ex, ma, ma, ma. fpu exception handling is not a delayed branch. the if stage of the branch destination instruction is started from the slot containing the last ma stage of the fpu exception handling. pipeline processing of instructions from generation to acceptance of fpu exceptions the fpu makes the instruction at which the execution occurred an nop instruction, and also makes fpu instructions (excluding fcmp instructions) from occurrence of the execution to the instruction that accepts the exception nop instructions. consequently, fpu registers are not updated by instructions during this interval. with fpu-related cpu instructions, as above, fpu registers are not updated (nop operation is performed), but cpu registers are updated. cpu instructions are not made nop instructions, and operate as usual.
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 448 of 484 rej09b0051-0300 8.9.8 floating-point instructions and fpu-related cpu instructions (1) fpul load instructions instruction types lds rm,fpul lds.l @rm+,fpul pipeline ??????? slots instruction a if id ex ma : cpu pipeline if df ex na sf : fpu pipeline next instruction if id ex ? ?? ? ? ?? ? ? ?? ? : cpu pipeline if df ? ?? ? ? ?? ? ? ?? ? : fpu pipeline instruction after next if id ex ? ?? ? ? ?? ? ? ?? ? : cpu pipeline if df ? ?? ? ? ?? ? ? ?? ? : fpu pipeline operation the cpu pipeline ends after four stages ? if, id, ex, ma ? and the fpu pipeline after five stages ? if, df, ex, na, sf. contention may occur if an instruction that reads fpul is located within the 3 instructions following one of these instructions. instruction issuance these instructions use the fpu load/store pipeline and memory access pipeline. there is no contention between an lds instruction and a cpu memory read instruction. parallel execution capability no particular comments
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 449 of 484 rej09b0051-0300 (2) fpscr load instructions instruction types lds rm,fpscr lds.l @rm+,fpscr pipeline ??????? slots instruction a if id ex ma : cpu pipeline if df ex na sf : fpu pipeline next instruction if ? id ex ? ?? ? ? ?? ? ? ?? ? : cpu pipeline if ? df ? ?? ? ? ?? ? ? ?? ? : fpu pipeline instruction after next if id ex ? ?? ? ? ?? ? ? ?? ? : cpu pipeline if df ? ?? ? ? ?? ? ? ?? ? : fpu pipeline operation the cpu pipeline ends after four stages ? if, id, ex, ma ? and the fpu pipeline after five stages ? if, df, ex, na, sf. a subsequent fpu-related instruction is stalled for the next 3 cycles. instruction issuance these instructions use the fpu load/store pipeline. the lds.l instruction also uses the memory access pipeline. if an fpu arithmetic operation instruction is still performing calculation, these instructions are kept waiting until that instruction ends. parallel execution capability these instructions cannot be executed in parallel with fpu instructions or fpu-related cpu instructions.
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 450 of 484 rej09b0051-0300 (3) fpul store instruction (sts) instruction type sts fpul,rn pipeline ??????? slots instruction a if id ex wb : cpu pipeline if df ex na : fpu pipeline next instruction if id ex ? ?? ? ? ?? ? ? ?? ? : cpu pipeline if df ? ?? ? ? ?? ? ? ?? ? : fpu pipeline instruction after next if id ex ? ?? ? ? ?? ? ? ?? ? : cpu pipeline if df ? ?? ? ? ?? ? ? ?? ? : fpu pipeline operation the cpu pipeline ends after four stages ? if, id, ex, wb ? and the fpu pipeline after four stages ? if, df, ex, na. contention may occur if an instruction that uses the destination of this instruction is located within the 3 instructions following this instruction. instruction issuance this instruction uses the multiplication result read path. this instruction uses the fpu load/store pipeline and memory access pipeline. there is no contention with a cpu memory write instruction. if fpul is waiting for the result of an fpu arithmetic operation, the latency of the previous instruction is reduced by 2. see section 8.6, contention due to fpu, for details. parallel execution capability no particular comments
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 451 of 484 rej09b0051-0300 (4) fpul store instruction (sts.l) instruction type sts.l fpul,@-rn pipeline ??????? slots instruction a if id ex ma : cpu pipeline if df ex na : fpu pipeline next instruction if id ex ? ?? ? ? ?? ? ? ?? ? : cpu pipeline if df ? ?? ? ? ?? ? ? ?? ? : fpu pipeline instruction after next if id ex ? ?? ? ? ?? ? ? ?? ? : cpu pipeline if df ? ?? ? ? ?? ? ? ?? ? : fpu pipeline operation the cpu pipeline ends after four stages ? if, id, ex, ma ? and the fpu pipeline after four stages ? if, df, ex, na. instruction issuance this instruction uses the fpu load/store pipeline and memory access pipeline. if fpul is waiting for the result of an fpu arithmetic operation, the latency of the previous instruction is reduced by 1. see section 8.6, contention due to fpu, for details. parallel execution capability no particular comments
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 452 of 484 rej09b0051-0300 (5) fpscr store instruction (sts) instruction type sts fpscr,rn pipeline ??????? slots instruction a if id ex wb : cpu pipeline if df ex na : fpu pipeline next instruction if ? id ex ? ?? ? ? ?? ? ? ?? ? : cpu pipeline if ? df ? ?? ? ? ?? ? ? ?? ? : fpu pipeline instruction after next if id ex ? ?? ? ? ?? ? ? ?? ? : cpu pipeline if df ? ?? ? ? ?? ? ? ?? ? : fpu pipeline operation the cpu pipeline ends after four stages ? if, id, ex, ma, wb ? and the fpu pipeline after four stages ? if, df, ex, na. contention may occur if an instruction that uses the destination of this instruction is located within the 3 instructions following this instruction. instruction issuance this instruction uses the multiplication result read path. if an fpu arithmetic operation instruction is still performing calculation, this instruction is kept waiting until that instruction ends. parallel execution capability this instruction cannot be executed in parallel with fpu instructions or fpu-related cpu instructions.
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 453 of 484 rej09b0051-0300 (6) fpscr store instruction (sts.l) instruction type sts.l fpscr,@-rn pipeline ??????? slots instruction a if id ex ma : cpu pipeline if df ex na : fpu pipeline next instruction if ? id ex ? ?? ? ? ?? ? ? ?? ? : cpu pipeline if ? df ? ?? ? ? ?? ? ? ?? ? : fpu pipeline instruction after next if id ex ? ?? ? ? ?? ? ? ?? ? : cpu pipeline if df ? ?? ? ? ?? ? ? ?? ? : fpu pipeline operation the cpu pipeline ends after four stages ? if, id, ex, ma ? and the fpu pipeline after four stages ? if, df, ex, na. instruction issuance this instruction uses the fpu load/store pipeline and memory access pipeline. if an fpu arithmetic operation instruction is still performing calculation, this instruction is kept waiting until that instruction ends. parallel execution capability this instruction cannot be executed in parallel with fpu instructions or fpu-related cpu instructions.
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 454 of 484 rej09b0051-0300 (7) some floating-point register-register transfer instructions, floating-point register- immediate instructions, and floating-point operation instructions instruction types flds frm,fpul fmov frm,frn fsts fpul,frn fldi0 frn fldi1 frn fabs frn fneg frn fabs drn fneg drn pipeline ??????? slots instruction a if id ex : cpu pipeline if df ex na sf : fpu pipeline next instruction if id ex ? ?? ? ? ?? ? ? ?? ? : cpu pipeline if df e1 e2 sf : fpu pipeline instruction after next if id ex ? ?? ? ? ?? ? ? ?? ? : cpu pipeline if df e1 e2 e3 : fpu pipeline operation the cpu pipeline ends after three stages ? if, id, ex ? and the fpu pipeline after five stages ? if, df, ex, na, sf. contention does not occur even if one of these instructions is immediately followed by an instruction that reads the destination of that instruction. instruction issuance these instructions use the fpu load/store pipeline. parallel execution capability these are zero-latency instructions. parallel execution is possible even if one of these instructions is executed as a preceding instruction and the succeeding instruction uses frn, fpul.
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 455 of 484 rej09b0051-0300 (8) double-precision floating-point register to register data transfer instructions instruction types fmov drm,drn pipeline ??????? slots instruction a if id ex ex : cpu pipeline if df ex ex na sf : fpu pipeline next instruction if ? ?? ? ? ?? ? ? ?? ? id ex ? ?? ? ? ?? ? ? ?? ? : cpu pipeline if ? ?? ? ? ?? ? ? ?? ? df e1 e2 sf : fpu pipeline instruction after next if ? ?? ? ? ?? ? ? ?? ? id ex ? ?? ? ? ?? ? ? ?? ? : cpu pipeline if ? ?? ? ? ?? ? ? ?? ? df e1 e2 sf : fpu pipeline operation the cpu pipeline ends after four stages ? if, id, ex, ex ? and the fpu pipeline after six stages ? if, df, ex, ex, na, sf. contention does not occur even if one of these instructions is immediately followed by an instruction that reads the destination of that instruction. instruction issuance this instruction uses the fpu load/store pipeline. parallel execution capability no particular comments
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 456 of 484 rej09b0051-0300 (9) fschg instruction instruction types fschg pipeline ??????? slots instruction a if id ex : cpu pipeline if df ex na sf : fpu pipeline next instruction if id ex ? ?? ? ? ?? ? ? ?? ? : cpu pipeline if df e1 e2 sf : fpu pipeline instruction after next if id ex ? ?? ? ? ?? ? ? ?? ? : cpu pipeline if df e1 e2 sf : fpu pipeline operation the cpu pipeline ends after three stages ? if, id, ex ? and the fpu pipeline after five stages ? if, df, ex, na, sf. contention does not occur even if one of these instructions is immediately followed by an instruction that reads the destination of that instruction. instruction issuance this instruction uses the fpu load/store pipeline. parallel execution capability no particular comments
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 457 of 484 rej09b0051-0300 (10) floating-point register load instructions instruction types fmov.s @rm,frn fmov.s @rm+,frn fmov.s @(r0,rm),frn fmov.d @rm,drn fmov.d @rm,drn fmov.d @(r0,rm),drn pipeline ? single-precision ??????? slots instruction a if id ex ma : cpu pipeline if df ex na sf : fpu pipeline next instruction if id ex ? ?? ? ? ?? ? ? ?? ? : cpu pipeline if df e1 e2 sf : fpu pipeline instruction after next if id ex ? ?? ? ? ?? ? ? ?? ? : cpu pipeline if df e1 e2 sf : fpu pipeline ? double-precision ??????? slots instruction a if id ex ma ma : cpu pipeline if df ex ex na sf : fpu pipeline next instruction if ? id ex ? ?? ? ? ?? ? ? ?? ? : cpu pipeline if ? df e1 e2 sf : fpu pipeline instruction after next if ? id ex ? ?? ? ? ?? ? ? ?? ? : cpu pipeline if ? df e1 e2 sf : fpu pipeline
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 458 of 484 rej09b0051-0300 operation ? single-precision the cpu pipeline ends after four stages ? if, id, ex, ma ? and the fpu pipeline after five stages ? if, df, ex, na, sf. contention may occur if an instruction that reads the destination of one of these instructions is located within the 3 instructions following that instruction. ? double-precision the cpu pipeline ends after five stages ? if, id, ex, ma, ma ? and the fpu pipeline after six stages ? if, df, ex, ex, na, sf. contention may occur if an instruction that reads the destination of one of these instructions is located within the 5 instructions following that instruction. instruction issuance these instructions use the fpu load/store pipeline and memory access pipeline. parallel execution capability fmov.d instruction is a multi-cycle instruction, and cannot be executed in parallel with a subsequent instruction. (see section 8.3.4, details of contention due to multi-cycle instruction.)
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 459 of 484 rej09b0051-0300 (11) floating-point register load instruction (12-bit displacement) instruction type fmov.s @(disp12,rm),frn fmov.d @(disp12,rm),drn pipeline ? single-precision ??????? slots instruction a if id ex ma : cpu pipeline if df ex na sf : fpu pipeline next instruction if id ex ? ?? ? ? ?? ? ? ?? ? : cpu pipeline if df ex na sf : fpu pipeline instruction after next if id ex ? ?? ? ? ?? ? ? ?? ? : cpu pipeline if df e1 e2 sf : fpu pipeline ? double-precision ???????? slots instruction a if id ex ma ma : cpu pipeline if df ex ex na sf : fpu pipeline next instruction if ? id ex ? ?? ? ? ?? ? ? ?? ? : cpu pipeline if ? df e1 e2 sf : fpu pipeline instruction after next if ? id ex ? ?? ? ? ?? ? ? ?? ? : cpu pipeline if ? df e1 e2 sf : fpu pipeline operation ? single-precision the cpu pipeline ends after four stages ? if, id, ex, ma ? and the fpu pipeline after five stages ? if, df, ex, na, sf. contention may occur if an instruction that reads the destination of this instruction is located within the 3 instructions following this instruction. ? double-precision the cpu pipeline ends after five stages ? if, id, ex, ma, ma ? and the fpu pipeline after six stages ? if, df, ex, ex, na, sf. contention may occur if an instruction that reads the destination of this instruction is located within the 3 instructions following this instruction.
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 460 of 484 rej09b0051-0300 instruction issuance these instructions use the fpu load/store pipeline and memory access pipeline. parallel execution capability this is a 32-bit instruction, and cannot be used in parallel execution. (see section 8.3.5, details of contention due to 32-bit instruction.)
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 461 of 484 rej09b0051-0300 (12) floating-point register store instructions instruction types fmov.s frm,@rn fmov.s frm,@-rn fmov.s frm,@(r0,rn) fmov.d drm,@rn fmov.d drm,@-rn fmov.d drm,@(r0,rn) pipeline ? single-precision ??????? slots instruction a if id ex ma : cpu pipeline if df ex na : fpu pipeline next instruction if ex ? ?? ? ? ?? ? ? ?? ? : cpu pipeline if e1 e2 sf : fpu pipeline instruction after next if id ex ? ?? ? ? ?? ? ? ?? ? : cpu pipeline if df e1 e2 sf : fpu pipeline ? double-precision ???????? slots instruction a if id ex ma ma : cpu pipeline if df ex ex na : fpu pipeline next instruction if ? id ex ? ?? ? ? ?? ? ? ?? ? : cpu pipeline if ? df e1 e2 sf : fpu pipeline instruction after next if ? id ex ? ?? ? ? ?? ? ? ?? ? : cpu pipeline if ? df e1 e2 sf : fpu pipeline
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 462 of 484 rej09b0051-0300 operation ? single-precision the cpu pipeline ends after four stages ? if, id, ex, ma ? and the fpu pipeline after four stages ? if, df, ex, na. ? double-precision the cpu pipeline ends after five stages ? if, id, ex, ma, ma ? and the fpu pipeline after five stages ? if, df, ex, ex, na. instruction issuance these instructions use the fpu load/store pipeline and memory access pipeline. parallel execution capability fmov.d instruction is a multi-cycle instruction, and cannot be executed in parallel with a subsequent instruction. (see section 8.3.4, details of contention due to multi-cycle instruction.)
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 463 of 484 rej09b0051-0300 (13) floating-point register store instruction (12-bit displacement) instruction type fmov.s frm,@(disp12,rn) fmov.d drm,@(disp12,rn) pipeline ? single-precision ??????? slots instruction a if id ex ma : cpu pipeline if df ex na : fpu pipeline next instruction if id ex ? ?? ? ? ?? ? ? ?? ? : cpu pipeline if df e1 e2 sf : fpu pipeline instruction after next if id ex ? ?? ? ? ?? ? ? ?? ? : cpu pipeline if df ex na sf : fpu pipeline ? double-precision ???????? slots instruction a if id ex ma ma : cpu pipeline if df ex ex na : fpu pipeline next instruction if ? id ex ? ?? ? ? ?? ? ? ?? ? : cpu pipeline if ? df e1 e2 sf : fpu pipeline instruction after next if ? id ex ? ?? ? ? ?? ? ? ?? ? : cpu pipeline if ? df e1 e2 sf : fpu pipeline operation ? single-precision the cpu pipeline ends after four stages ? if, id, ex, ma ? and the fpu pipeline after four stages ? if, df, ex, na. ? double-precision the cpu pipeline ends after five stages ? if, id, ex, ma, ma ? and the fpu pipeline after five stages ? if, df, ex, ex, na.
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 464 of 484 rej09b0051-0300 instruction issuance these instructions use the fpu load/store pipeline and memory access pipeline. parallel execution capability this is a 32-bit instruction, and cannot be used in parallel execution. (see section 8.3.5, details of contention due to 32-bit instruction.)
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 465 of 484 rej09b0051-0300 (14) floating-point operation instructions (excluding fdiv, fsqrt, float, and ftrc) instruction types fadd frm,frn fmac fr0,frm,frn fmul frm,frn fsub frm,frn fadd drm,drn fmul drm,drn fsub drm,drn pipeline ? single-precision ??????? slots instruction a if id ex : cpu pipeline if df e1 e2 sf : fpu pipeline next instruction if id ex ? ?? ? ? ?? ? ? ?? ? : cpu pipeline if df ex na sf : fpu pipeline instruction after next if id ex ? ?? ? ? ?? ? ? ?? ? : cpu pipeline if df ex na sf : fpu pipeline ? double-precision ??????????? slots instruction a if id ex : cpu pipeline if df e1 e1 e1 e1 e1 e1 e2 sf : fpu pipeline next instruction if id ex ma wb : cpu pipeline if df ex na sf : fpu pipeline instruction after next if id ex ? ?? ? ? ?? ? ? ?? ? : cpu pipeline if df ex na sf : fpu pipeline
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 466 of 484 rej09b0051-0300 operation ? single-precision the cpu pipeline ends after three stages ? if, id, ex ? and the fpu pipeline after five stages ? if, df, e1, e2, sf. contention may occur if an instruction that reads the destination of one of these instructions is located within the 5 instructions following that instruction. ? double-precision the cpu pipeline ends after three stages ? if, id, ex ? and the fpu pipeline after 10 stages ? if, df, e1, e1, e1, e1, e1, e1, e2, sf. contention may occur if an instruction that reads the destination of one of these instructions is located within the 15 instructions following that instruction. instruction issuance these instructions use the fpu arithmetic operation pipeline. see section 8.6, contention due to fpu, for details of contention. parallel execution capability no particular comments
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 467 of 484 rej09b0051-0300 (15) floating-point operation instructions (float, ftrc) and fcnvsd, fcnvds instructions instruction types float fpul,frn ftrc drm,fpul float fpul,drn ftrc drm,fpul fcnvsd fcnvds pipeline ? single-precision ??????? slots instruction a if id ex : cpu pipeline if df e1 e2 sf : fpu pipeline next instruction if id ex ? ?? ? ? ?? ? ? ?? ? : cpu pipeline if df ex na sf : fpu pipeline instruction after next if id ex ? ?? ? ? ?? ? ? ?? ? : cpu pipeline if df e1 e2 sf : fpu pipeline ? double-precision ??????????? slots instruction a if id ex : cpu pipeline if df e1 e1 e2 sf : fpu pipeline next instruction if id ex ma wb : cpu pipeline if df ex na sf : fpu pipeline instruction after next if id ex ? ?? ? ? ?? ? ? ?? ? : cpu pipeline if df ex na sf : fpu pipeline
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 468 of 484 rej09b0051-0300 operation ? single-precision the cpu pipeline ends after three stages ? if, id, ex ? and the fpu pipeline after five stages ? if, df, e1, e2, sf. contention may occur if an instruction that reads the destination of one of these instructions is located within the 5 instructions following that instruction. ? double-precision the cpu pipeline ends after three stages ? if, id, ex ? and the fpu pipeline after six stages ? if, df, e1, e1, e2, sf. contention may occur if an instruction that reads the destination of one of these instructions is located within the 7 instructions following that instruction. instruction issuance these instructions use the fpu arithmetic operation pipeline. see section 8.6, contention due to fpu, for details of contention. parallel execution capability no particular comments
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 469 of 484 rej09b0051-0300 (16) floating-point operation instructions (fdiv) instruction types fdiv frm,frn fdiv drm,drn pipeline ? single-precision ?????????????? slots instruction a if id ex : cpu pipeline if df e1 ed ed ed ed ed ed ed ed e1 e2 sf : fpu pipeline next instruction if id ex ? ?? ? ? ?? ? ? ?? ? : cpu pipeline if df ex na sf : fpu pipeline instruction after next if id ex ? ?? ? ? ?? ? ? ?? ? : cpu pipeline if df ex na sf : fpu pipeline ? double-precision ?????????????? slots instruction a if id ex : cpu pipeline if df e1 e1 ed ? ?? ? ? ?? ? ? ?? ? ed e1 e1 e1 e2 sf : fpu pipeline next instruction if id ex ? ?? ? ? ?? ? ? ?? ? : cpu pipeline if df ex na sf : fpu pipeline instruction after next if id ex ? ?? ? ? ?? ? ? ?? ? : cpu pipeline if df ex na sf : fpu pipeline
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 470 of 484 rej09b0051-0300 operation ? single-precision the cpu pipeline ends after three stages ? if, id, ex ? and the fpu pipeline after 14 stages ? if, df, e1, ed, ed, ed, ed, ed, ed, ed, ed, e1, e2, sf. that is to say, after one e1 stage has been performed, the ed stage is repeated 8 times, followed by e1, e2, and sf. ? double-precision the cpu pipeline ends after three stages ? if, id, ex ? and the fpu pipeline after 27 stages ? if, df, e1, e1, ed, ed, ed, ed, ed, ed, ed, ed, ed, ed, ed, ed, ed, ed, ed, ed, ed, ed, e1, e1, e1, e2, sf. that is to say, after the e1 stage has been performed twice, the ed stage is repeated 18 times, followed by e1, e1, e1, e2, and sf. the contention described in section 8.6, contention due to fpu, occurs. if there is an overlapping instruction that accesses the fdiv result register in the fdiv pipeline, that instruction is kept waiting until execution of the fdiv instruction is finished. stages from e1 onward are stalled until the end of fdiv execution, and subsequent instructions are also subject to stalling. therefore, if a floating-point instruction that uses the fdiv result register, or an fpu-related cpu instruction, is not located within 21 instructions immediately after the fdiv instruction in the case of single-precision, or 49 instructions in the case of double-precision, a cpu instruction or another fpu instruction can be executed during that interval, enabling performance to be improved. instruction issuance these instructions use the fpu arithmetic operation pipeline. see section 8.6, contention due to fpu, for details of contention. the ed stages of these instructions operate in states, without regard to slots. parallel execution capability no particular comments
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 471 of 484 rej09b0051-0300 (17) floating-point operation instructions (fsqrt) instruction types fsqrt frn fsqrt drn pipeline ? single-precision ?????????????? slots instruction a if id ex : cpu pipeline if df e1 ed ed ed ed ed ed ed e1 e2 sf : fpu pipeline next instruction if id ex ? ?? ? ? ?? ? ? ?? ? : cpu pipeline if df ex na sf : fpu pipeline instruction after next if id ex ? ?? ? ? ?? ? ? ?? ? : cpu pipeline if df ex na sf : fpu pipeline ? double-precision ?????????????? slots instruction a if id ex : cpu pipeline if df e1 e1 ed ? ?? ? ? ?? ? ? ?? ? ed e1 e1 e1 e2 sf : fpu pipeline next instruction if id ex ? ?? ? ? ?? ? ? ?? ? : cpu pipeline if df ex na sf : fpu pipeline instruction after next if id ex ? ?? ? ? ?? ? ? ?? ? : cpu pipeline if df ex na sf : fpu pipeline
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 472 of 484 rej09b0051-0300 operation ? single-precision the cpu pipeline ends after three stages ? if, id, ex ? and the fpu pipeline after 13 stages ? if, df, e1, ed, ed, ed, ed, ed, ed, ed, e1, e2, sf. that is to say, after one e1 stage has been performed, the ed stage is repeated 7 times, followed by e1, e2, and sf. ? double-precision the cpu pipeline ends after three stages ? if, id, ex ? and the fpu pipeline after 26 stages ? if, df, e1, e1, ed, ed, ed, ed, ed, ed, ed, ed, ed, ed, ed, ed, ed, ed, ed, ed, ed, e1, e1, e1, e2, sf. that is to say, after the e1 stage has been performed twice, the ed stage is repeated 17 times, followed by e1, e1, e1, e2, and sf. the contention described in section 8.6, contention due to fpu, occurs. if there is an overlapping instruction that accesses the fsqrt result register in the fsqrt pipeline, that instruction is kept waiting until execution of the fsqrt instruction is finished. stages from e1 onward are stalled until the end of fsqrt execution, and subsequent instructions are also subject to stalling. therefore, if a floating-point instruction that uses the fsqrt result register, or an fpu-related cpu instruction, is not located within 19 instructions immediately after the fsqrt instruction in the case of single-precision, or 47 instructions in the case of double-precision, a cpu instruction or another fpu instruction can be executed during that interval, enabling performance to be improved. instruction issuance these instructions use the fpu arithmetic operation pipeline. see section 8.6, contention due to fpu, for details of contention. the ed stages of these instructions operate in states, without regard to slots. parallel execution capability no particular comments
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 473 of 484 rej09b0051-0300 (18) floating-point compare instructions instruction types fcmp/eq frm,frn fcmp/gt frm,frn fcmp/eq drm,drn fcmp/gt drm,drn pipeline ? single-precision ??????? slots instruction a if id ex : cpu pipeline if df e1 e2 : fpu pipeline next instruction if id ex ? ?? ? ? ?? ? ? ?? ? : cpu pipeline if df ex na sf : fpu pipeline instruction after next if id ex ? ?? ? ? ?? ? ? ?? ? : cpu pipeline if df e1 e2 sf : fpu pipeline ? double-precision ??????? slots instruction a if id ex ex : cpu pipeline if df e1 e1 e2 : fpu pipeline next instruction if ? id ex ? ?? ? ? ?? ? ? ?? ? : cpu pipeline if ? df ex na sf : fpu pipeline instruction after next if ? id ex ? ?? ? ? ?? ? ? ?? ? : cpu pipeline if ? df ex na sf : fpu pipeline
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 474 of 484 rej09b0051-0300 operation ? single-precision the cpu pipeline ends after three stages ? if, id, ex ? and the fpu pipeline after four stages ? if, df, e1, e2. as the t bit is checked in e2, an instruction that references the t bit immediately afterward is stalled for 2 cycles. fcmp if id ex : cpu pipeline if df e1 e2 : fpu pipeline bt if ? ? id ex : cpu pipeline if ? ? df ? ?? ? ? ?? ? ? ?? ? : fpu pipeline operation ? double-precision the cpu pipeline ends after four stages ? if, id, ex, ex ? and the fpu pipeline after five stages ? if, df, e1, e1, e2. as the t bit is checked in e2, an instruction that references the t bit immediately afterward is stalled for 3 cycles. fcmp if id ex : cpu pipeline if df e1 e1 e2 : fpu pipeline bt if ? ? ? id ex : cpu pipeline if ???df ? ?? ? ? ?? ? ? ?? ? : fpu pipeline instruction issuance these instructions use the fpu arithmetic operation pipeline. parallel execution capability parallel execution of a double-precision fcmp instruction and the following instruction is not possible.
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 475 of 484 rej09b0051-0300 8.10 simple method of calculating required number of clock cycles a simple method of calculating required number of clock cycles is described below. this method provides a rough approximation, but it allows the user to calculate the number of clock cycles needed to execute the target instruction string. the calculation is based on the following rules. (1) the instructions are assumed to already have been fetched, so fetch time is not taken into consideration. (2) the 32-bit instructions operate in ?execution state? cycles. (3) if resource contention occurs, the previously issued instructions operate in ?execution state? cycles. parallel execution of subsequent instructions is not possible. (4) if the result from the previously issued instruction is used by the instruction that immediately follows, the calculation assumes that the previously issued instruction will require ?latency? cycles. (5) if the result from the previously issued instruction is not used by the instruction that immediately follows, the calculation assumes that the previously issued instruction will require ?execution state? cycles. (6) correction for parallel execution is performed in simplified form as a compensation item. there are a large number of exceptional cases, so the calculation method introduced here cannot be 100% accurate. it does allow the user to obtain a rough idea of the number of clock cycles that will be required, however. examples are provided below. 1. counting latency cycles ???????? cycles mov.l @ r1, r0 id ex ma wb 2 add # imm, r0 ? ? id ex 1 mov.l r0, @ r1 ? id ex ma the result from mov.l, which precedes add, will be used, so the calculation assumes that mov.l will require ?latency? cycles (two cycles) to execute. the next mov.l instruction uses the result from add, so the calculation assumes that the add instruction will require ?latency? execution (one cycle).
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 476 of 484 rej09b0051-0300 2. counting execution state cycles ???????? cycles mov.l @ r1, r0 id ex ma wb 1 0 add # imm, r2 id ex 1 mov.l r3, @ r4 id ex ma in this case, the result from the previously issued instruction is not used by the instructions that follow it, so the instructions execute in parallel provided no resource contention occurs. the number of cycles required by each instruction to execute are calculated in the ?execution state.? when the preceding instruction uses one execution state cycle, the following instruction executes in parallel. when parallel execution takes place, the number of cycles required by the preceding instruction is calculated as ?execution state? minus one. this serves as a simplified compensation. (this compensation appears as the final item in the equation introduced below.) 3. if resource contention occurs ???????? cycles mov.l @ r1, r0 id ex ma wb 1 mov.l @ r3, r2 id ex ma wb 1 mov.l @ r5, r4 id ex ma wb if resource contention occurs, parallel execution is not possible. the execution of each instruction requires ?execution state? cycles. 4. instructions using more than one execution state ? ??????? cycles and.b # imm, @(r0,gbr) id ex ma ex 3 2 add # imm, r1 id ex 1 band.b # imm, @(disp12,r2) id ex ma ex 3 rotcl id for instructions using more than one execution state, the calculation assumes that the number of remaining states is reduced one by one until only one remains, at which point parallel execution with the subsequent instructions is possible. in this case, the number of cycles required for execution is calculated as ?execution state? minus one if parallel execution with subsequent instructions takes place, and as ?execution state? if no parallel execution takes place. this serves
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 477 of 484 rej09b0051-0300 as a simplified compensation. (this compensation appears as the final item in the equation introduced below.) based on the above, the number of cycles necessary to execute the entire instruction string is as summarized below, in extremely simplified terms. if some portions of the string have dependencies and others do not, separate calculations should be made for each portion and the results added together. ? if dependencies exist between instructions required number of cycles = sum total of ?latency? cycles of all instructions ? if no dependencies exist between instructions required number of cycles = sum total of ?execution state? cycles of all instructions? (total number of instructions ? number of instructions that cannon be executed in parallel) 2 in this case, ?number of instructions that cannon be executed in parallel? is the total number of instructions that cannot be executed in parallel due to resource contention (in particular, memory access instructions that immediately follow another memory access instruction), instructions using more than one execution state, and 32-bit instructions the final item compensates for the effects of parallel execution by reducing the number of required cycles for the preceding instructions. example: if dependencies exist between instructions band.b rotcl band.b rotcl the ?latency? cycles for all instructions are added together, producing a total of eight cycles. example: if no dependencies exist between instructions add # imm, r0 band.b # imm, @(disp12,r2) mulr r4, r0 rotcl r5 required number of cycles = 1 + 3 + 2 + 1 ? (4 ? 2) 2 = 7 ? 1 = 6 cycles
section 8 pipeline operation rev. 3.00 jul 08, 2005 page 478 of 484 rej09b0051-0300
appendix a SH-2A/sh2a-fpu parallel execution rev. 3.00 jul 08, 2005 page 479 of 484 rej09b0051-0300 appendix a SH-2A/sh2a-fpu parallel execution the table below can be used to determine whether or not parallel execution is supported, depending on the type of arithmetic unit used. in the case of instructions that belong to more than one category, parallel execution is supported if all of the applicable intersections are marked with a circle ( o ). second instruction (1) br (2) mr (3) mw (4) mf (5) ml (6) mu (7) sf (8) fl (9) fp (10) fc (11) ex (1) br oooooooooo (2) mr o oooooooo (3) mw o ooooooo (4) mf oo ooooooo (5) ml oooo oooooo (6) mu ooooo ooooo (7) sf oooooo oooo (8) fl ooooooo o o (9) fp oooooooo o (10) fc first instruction (11) ex ooooooooooo classifi- cation of first instruction classifi- cation of second instruction instruction br br bf disp bf/s disp bt disp bt/s disp bsr disp bsrf rm bra disp braf rm jmp @rm jsr @rm jsr/n @rm rts rts/n rtv/n rm trapa #imm mr mr ldc.l @rm+,gbr ldc.l @rm+,vbr lds.l @rm+,pr mov.b @(disp,gbr),r0 mov.b @(disp,rm),r0 mov.b @(r0,rm),rn mov.b @rm,rn mov.b @rm+,rn mov.b @-rm,r0 mov.b @(disp12,rm),rn mov.w @(disp,gbr),r0 mov.w @(disp,rm),r0 mov.w @(r0,rm),rn mov.w @rm,rn mov.w @rm+,rn mov.w @-rm,r0 mov.w @(disp12,rm),rn mov.w @(disp,pc),rn mov.l @(disp,gbr),r0 mov.l @(disp,rm),rn mov.l @(r0,rm),rn mov.l @rm,rn mov.l @rm+,rn mov.l @-rm,r0 mov.l @(disp12,rm),rn mov.l @(disp,pc),rn movu.b @(disp12,rm),rn movu.w @(disp12,rm),rn movml.l @r15+,rn movmu.l @r15+,rn pref @rn
appendix a SH-2A/sh2a-fpu parallel execution rev. 3.00 jul 08, 2005 page 480 of 484 rej09b0051-0300 classifi- cation of first instruction classifi- cation of second instruction instruction mw mr and.b #imm,@(r0,gbr) bclr.b #imm3,@(disp12,rn) bset.b #imm3,@(disp12,rn) bst.b #imm3,@(disp12,rn) or.b #imm,@(r0,gbr) stc.l sr,@-rn tas.b @rn xor.b #imm,@(r0,gbr) mw mw mov.b r0,@(disp,gbr) mov.b r0,@(disp,rn) mov.b rm,@(r0,rn) mov.b rm,@rn mov.b rm,@-rn mov.b r0,@rn+ mov.b rm,@(disp12,rn) mov.w r0,@(disp,gbr) mov.w r0,@(disp,rn) mov.w rm,@(r0,rn) mov.w rm,@rn mov.w rm,@-rn mov.w r0,@rn+ mov.w rm,@(disp12,rn) mov.l r0,@(disp,gbr) mov.l rm,@(disp,rn) mov.l rm,@(r0,rn) mov.l rm,@rn mov.l rm,@-rn mov.l r0,@rn+ mov.l rm,@(disp12,rn) movml.l rm,@-r15 movmu.l rm,@-r15 stc.l gbr,@-rn stc.l vbr,@-rn sts.l pr,@-rn ml ml sts mach,rn sts macl,rn mu mu clrmac dmuls.l rm,rn dmulu.l rm,rn mul.l rm,rn muls.w rm,rn mulu.w rm,rn lds rm,macl lds rm,mach ml,mu ml mulr r0,rn sf sf divu r0,rn exts.b rm,rn exts.w rm,rn extu.b rm,rn extu.w rm,rn rotcl rn rotcr rn rotl rn rotr rn shad rm,rn shal rn shar rn shld rm,rn shll rn shll16 rn shll2 rn shll8 rn shlr rn shlr16 rn shlr2 rn shlr8 rn swap.b rm,rn swap.w rm,rn xtrct rm,rn fl fl fabs drn fabs frn fldi0 frn fldi1 frn flds frm,fpul fmov drm,drn fmov frm,frn fneg drn fneg frn fsts fpul,frn ml,fl ml,fl sts fpul,rn fp fp fadd drm,drn fadd frm,frn fcmp/eq frm,frn fcmp/gt frm,frn fcnvds drm,fpul fcnvsd fpul,drn fdiv drm,drn fdiv frm,frn float fpul,drn float fpul,frn fmac fr0,frm,frn fmul drm,drn fmul frm,frn fschg fsqrt drn fsqrt frn fsub drm,drn fsub frm,frn ftrc drm,fpul ftrc frm,fpul
appendix a SH-2A/sh2a-fpu parallel execution rev. 3.00 jul 08, 2005 page 481 of 484 rej09b0051-0300 classifi- cation of first instruction classifi- cation of second instruction instruction fc fc fcmp/eq drm,drn fcmp/gt drm,drn ml,fc ml,fc sts fpscr,rn ex ex add #imm,rn add rm,rn addc rm,rn addv rm,rn and #imm,r0 and rm,rn bclr #imm3,rn bld #imm3,rn bset #imm3,rn bst #imm3,rn clrt cmp/eq #imm,r0 cmp/eq rm,rn cmp/ge rm,rn cmp/gt rm,rn cmp/hi rm,rn cmp/hs rm,rn cmp/pl rn cmp/pz rn cmp/str rm,rn clips.b rn clips.w rn clipu.b rn clipu.w rn div0s rm,rn div0u divs r0,rn div1 rm,rn dt rn ldc rm,gbr ldc rm,sr ldc rm,tbr ldc rm,vbr lds rm,pr ldbank @rm,r0 mov #imm,rn mov rm,rn mova @(disp,pc),r0 movi20 #imm20,rn movi20s #imm20,rn movt rn movrt rn neg rm,rn negc rm,rn nop not rm,rn nott or #imm,r0 or rm,rn sett stc gbr,rn stc sr,rn stc tbr,rn stc vbr,rn sts pr,rn stbank r0,@rn sub rm,rn subc rm,rn subv rm,rn tst #imm,r0 tst rm,rn xor #imm,r0 xor rm,rn resbank(bo==0) mr,mu mr,mu lds.l @rm+,mach lds.l @rm+,macl mw.ml mw,ml sts.l mach,@-rn sts.l macl,@-rn mw,fl mw,fl fmov.s @(r0,rm),frn fmov.s @rm,frn fmov.s @rm+,frn fmov.s @(disp12,rm),frn fmov.s frm,@(r0,rn) fmov.s frm,@-rn fmov.s frm,@rn fmov.s frm,@(disp12,rn) fmov.d @(r0,rm),drn fmov.d @rm,drn fmov.d @rm+,drn fmov.d @(disp12,rm),drn fmov.d drm,@(r0,rn) fmov.d drm,@-rn fmov.d drm,@rn fmov.d drm,@(disp12,rn) mf,fl mf,fl lds rm,fpul mf,fc mf,fc lds rm,fpscr mr,fc mr,fc lds.l @rm+,fpscr lds.l @rm+,fpul mw,ml,fc mw,ml,fc sts.l fpscr,@-rn sts.l fpul,@-rn br mr jsr/n @@(disp8,tbr)
appendix a SH-2A/sh2a-fpu parallel execution rev. 3.00 jul 08, 2005 page 482 of 484 rej09b0051-0300 classifi- cation of first instruction classifi- cation of second instruction instruction mr,mu mr resbank(bo==1) ex mr band.b #imm3,@(disp12,rn) bandnot.b #imm3,@(disp12,rn) bld.b #imm3,@(disp12,rn) bldnot.b #imm3,@(disp12,rn) bor.b #imm3,@(disp12,rn) bornot.b #imm3,@(disp12,rn) bxor.b #imm3,@(disp12,rn) ldc.l @rm+,sr rte sleep tst.b #imm,@(r0,gbr) mu mr mac.w @rm+,@rn+ mac.l @rm+,@rn+ ? the first and last steps of multi-step instructions are executed in parallel. ? fpu instructions follow the sh4 classifications ((1) ls type, (2) fe type, (3) co type). the new 32-bit fmov instructions belong to the (1) ls type. ? as a rule, 32-bit instructions are executed in parallel if the preceding instruction is a multi-step instruction. they cannot be executed in parallel with the instructions that follow them. however, pairs of memory-tbit bit- manipulation instructions are executed in parallel. ? the movmu.l and movml.l instructions cannot be executed in parallel with the instructions that follow them. ? parallel execution of delayed branch instructions and delayed slots is not supported. multi-step instructions: trapa, movmu.l, movml.l, and.b, or.b, tst.b, xor.b, tas.b, bclr.b, bset.b, bst.b, band.b, bandnot.b, bld.b, bldnot.b, bor.b, bornot.b, bxor.b, mul.l, dmuls.l, dmulu.l, mulr, divu, divs, fcmp/eq drm,drn, fcmp/gt drm,drn, ldc rm,sr, stc sr,rn, ldc.l @rm+,sr, stc.l sr,@-rn, ldbank, stbank, resbank, fmov.d, fmov drm,drn, jsr/n @@(disp,tbr), sleep, rte, mac.w, mac.l 32-bit instructions: movi20, movi20s, mov.b @(disp12,rm),rn, mov.w @(disp12,rm),rn, mov.l @(disp12,rm),rn, mov.b rm,@(disp12,rn), mov.w rm,@(disp12,rn), mov.l rm,@(disp12,rn),movu.b, movu.w, fmov.s @(disp12,rm),frn, fmov.d @(disp12,rm),drn, fmov.s frm,@(disp12,rn), fmov.d drm,@(disp12,rn), bclr.b, bset.b, bst.b, band.b, bandnot.b, bld.b, bldnot.b, bor.b, bornot.b, bxor.b 32-bit fmov instructions: fmov.s @(disp12,rm),frn, fmov.d @(disp12,rm),drn, fmov.s frm,@(disp12,rn), fmov.d drm,@(disp12,rn), memory-tbit bit-manipulation instructions: band.b, bandnot.b, bld.b, bldnot.b, bor.b, bornot.b, bxor.b delayed branch instructions: bra, bsr, braf, bsrf, jmp, jsr, rts, rte, bt/s, bf/s
appendix b programming guidelines (using movi20 and movi20s) rev. 3.00 jul 08, 2005 page 483 of 484 rej09b0051-0300 appendix b programming guidelines (using movi20 and movi20s) in the SH-2A/sh2a-fpu, the movi20 #imm20,rn and movi20s #imm20,rn instructions reduce literal access by pc-relative instructions and increase cycle performance. use of a declaration of the sort shown below in the assembler is recommended in order to gain these benefits. (1) using movi20 movi20 performs sign extension. this instruction can be used to express the range h'00000000 to h'0007ffff and h'fff80000 to h'ffffffff. the following instruction string should be arranged continuously. movi20 #imm20, rn unconditional branch instruction* example: movi20 #imm20, rn jmp @ rm (2) using movi20s movi20s performs sign extension. this instruction can be used with add #imm, rn to express the range h'00000000 to h'07ffff7f and h'f7ffff80 to h'ffffffff. the following instruction string should be arranged continuously. movi20s #imm20, rn add#imm, rn unconditional branch instruction* example: movi20s#imm20, rn add#imm, rn jmp @ rm
appendix b programming guidelines (using movi20 and movi20s) rev. 3.00 jul 08, 2005 page 484 of 484 rej09b0051-0300 notes: to specify addresses in the range h'07ff ff80?h'07ff ffff: movi20s #imm20, r0 or #imm, r0 unconditional branch instruction * alternately, use a 32-bit address read as follows: mov.l @(disp, pc), rn unconditional branch instruction * * unconditional branch instruction: braf rm, bsrf rm, jmp @rm, jsr @rm, jsr/n @rm
renesas 32-bit risc microcomputer software manual SH-2A, sh2a-fpu publication date: 1st edition, march, 2004 rev.3.00, july 08, 2005 published by: sales strategic planning div. renesas technology corp. edited by: technical documentation & information department renesas kodaira semiconductor co., ltd. ? 2005. renesas technology corp. all rights reserved. printed in japan.
sales strategic planning div. nippon bldg., 2-6-2, ohte-machi, chiyoda-ku, tokyo 100-0004, japan http://www.renesas.com refer to " http://www.renesas.com/en/network " for the latest and detailed information. renesas technology america, inc. 450 holger way, san jose, ca 95134-1368, u.s.a tel: <1> (408) 382-7500, fax: <1> (408) 382-7501 renesas technology europe limited dukes meadow, millboard road, bourne end, buckinghamshire, sl8 5fh, united kingdom tel: <44> (1628) 585-100, fax: <44> (1628) 585-900 renesas technology hong kong ltd. 7th floor, north tower, world finance centre, harbour city, 1 canton road, tsimshatsui, kowloon, hong kong tel: <852> 2265-6688, fax: <852> 2730-6071 renesas technology taiwan co., ltd. 10th floor, no.99, fushing north road, taipei, taiwan tel: <886> (2) 2715-2888, fax: <886> (2) 2713-2999 renesas technology (shanghai) co., ltd. unit2607 ruijing building, no.205 maoming road (s), shanghai 200020, china tel: <86> (21) 6472-1001, fax: <86> (21) 6415-2952 renesas technology singapore pte. ltd. 1 harbour front avenue, #06-10, keppel bay tower, singapore 098632 tel: <65> 6213-0200, fax: <65> 6278-8001 renesas technology korea co., ltd. kukje center bldg. 18th fl., 191, 2-ka, hangang-ro, yongsan-ku, seoul 140-702, korea tel: <82> 2-796-3115, fax: <82> 2-796-2145 renesas technology malaysia sdn. bhd. unit 906, block b, menara amcorp, amcorp trade centre, no.18, jalan persiaran barat, 46050 petaling jaya, selangor darul ehsan, malaysia tel: <603> 7955-9390, fax: <603> 7955-9510 renesas sales offices colophon 3.0
SH-2A, sh2a-fpu software manual


▲Up To Search▲   

 
Price & Availability of SH-2A

All Rights Reserved © IC-ON-LINE 2003 - 2022  

[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy]
Mirror Sites :  [www.datasheet.hk]   [www.maxim4u.com]  [www.ic-on-line.cn] [www.ic-on-line.com] [www.ic-on-line.net] [www.alldatasheet.com.cn] [www.gdcy.com]  [www.gdcy.net]


 . . . . .
  We use cookies to deliver the best possible web experience and assist with our advertising efforts. By continuing to use this site, you consent to the use of cookies. For more information on cookies, please take a look at our Privacy Policy. X